Things about Git
matheuslima.com
matheuslima.com
You don't lose a commit just because you use git reset --hard. The author either doesn't know how git branches work and/or how to use reflog, or he means to say he lost the uncommitted content of his working tree.
git reflog
Might be your saviour here next time.When you do this by mistake and you don't know the hash you can find it using git reflog, which logs everything that happens in the repository.
More detailed: http://gitready.com/intermediate/2009/02/09/reflog-your-safe...
These days there's little reason to do reset --hard. `git reset --merge` is much safer and can be used almost anytime you would have otherwise done `--hard`.
e.g. if you want to force your branch to point at "foo", you can `git reset --merge foo` and it'll bail out if it detects that you have uncommitted edits that would have been lost by moving to "foo". If it can safely move the uncommitted edits there, it'll do it.
This won't give you the difference between two branches, it will give you the commits in the second branch which are not in the first one (technically it will give you the commits accessible from the second revspec which are not reachable from the first one, they need not be branches).
This means you won't see things in branch1 which have changed since the branches split.
If you want to see the differences between the two branches, you need to use <rev1>...<rev2> (three dots)
In set-theoretic notation, the first one is `a(branch2) \ a(branch1)` while the second one is `a(branch1) △ a(branch 2)` (where a is the ancestors-and-self function)
> Most people just use git status, but you can pass arguments to change the way status is shown. With git status -sb you have an output like this:
> ## master > M Gemfile > M Gemfile.lock > M app/controllers/home_controller.rb > M app/views/home/index.html.erb
This is mixing 2 changes and missing important information:
-s will provide what most people are looking for here, that is an SVN-like "short status" with no prose or suggestion text. Because of the index, Git has 2 status flags, the index state (difference between repository and index) and the second one is the working copy state (difference between working copy and index). The flags also feature specific states for merging situations.
-b adds branch information to the short status format, as `local[...remote]` (with the remote being absent if the local branch has no configured upstream).
Mercurial?!
> git again
Aw.
It may be interesting to compare the safety nets that Git and Mercurial provides. Mercurial tries to steer you away from rewriting history, but it does supply a complete set of tools for doing it - it has rebase, strip, commit --amend and so on. The difference is in what happens to deleted history.
In Git, as i understand it, history is defined by the branch pointers and the commits reachable from those. Deleting history simply means fiddling the branch pointers; the underlying commits are still there, completely unchanged. But now you can only find them via the reflog (unless you wrote their hashes down or something). They will stay there until the next garbage collection cycle. I don't know what determines when garbage collection occurs, so that might be ages, or it might not be long.
In Mercurial, history is defined by the commit graph. If something is in the graph, it's in history. That means that to delete something from history, you need to actually remove it from the graph. Commits which are removed are written as bundle files to the .strip-backup directory inside the repository's .hg directory. These are compressed binary files, so they're not much fun to look at directly, and i'm not aware of any way to display their contents, but Mercurial can import them, so restoring the changes. These files are never deleted automatically.
Really, Git's safety net is more tractable - once you have identified a deleted commit, you can work with it in the same way as any other commit. Mercurial's safety net is purely cold storage. I believe this reflects the tools' different opinions on rewriting history: in Git, it's normal, so you'll need the safety net a lot, whereas in Mercurial, it's not normal, so you will only need it if you have been bad, and you should feel bad.
Fortunately, something that is slowly arriving in Mercurial is the concept of changeset evolution:
http://mercurial.selenic.com/wiki/ChangesetEvolution
Which basically keeps deleted commits in the tree, like Git, but marks them as deleted. Moreover, when you do things like amend or rebase, it marks commits as having been replaced by other commits. Those marks are in the committed metadata, and are propagated between repositories, which means it becomes possible to do things like safely rebase public commits, merge different attempts at rebasing some commits, and more besides. If changeset evolution works as well as is hoped, it will provide all the advantages of history mutation without any of the drawbacks, which will be super sweet.
http://blog.nicoschuele.com/posts/git-2-0-changes-push-defau...
Is Git 1.9.2 (latest binary release for Windows) actually Git 2.x? By definition, shouldn't 1.9 do matching rather than simple?
git checkout -
to switch to the previous branch. Similarily, git merge -
to merge the previous branch into the current branch.I'm a enthusiastic git user, and I've ranted about a few git topics here: http://gitdoctor.com/
I also use the @gitdoctor twitter handle for helping people out in those moments of "oh shit, what is happening?!" with git :-)
I usually just create a temporary branch that I push upstream if I want to save my 'stash'. Is there a use case I'm not thinking of where pushing a stash upstream is useful?
Its pretty easy to turn one into a branch too if you feel you should make a stash available over the net.