Reputation: 5333
Do mercurial and git store a record of what changesets you were on before recent calls to update/checkout
? Is that history stored somewhere?
A concrete use case is if you pull/fetch
new work on a project and run into a problem with some of the new changes. Such a history would let you update back to where you were, in order to reverse the change without trial and error.
Upvotes: 2
Views: 91
Reputation: 489113
As distributed, Mercurial does not store information about which revisions you had checked out previously—but there is an experimental extension as of Mercurial 3.9 called Journal that, if enabled, does. Note too that hg pull
does not update to any new reference unless you tell it to, i.e., it's much more like git fetch
than it is like git pull
.1
Git does store this information, in the reflog for the special reference name HEAD
.2 This does depend on reflogs being enabled; you can disable them. The default for a normal working repository is to have them enabled.
After a git merge
or git rebase
(i.e., the second half of git pull
), HEAD@{1}
extracts the first entry in the reflog. Assuming you did a successful merge or rebase (so the immediately-previous value of HEAD
is the old reference), that gets you the previous HEAD
. If you did a rebase, and it failed and needed human assistance, the previous HEAD
is further back in the reflog, but ORIG_HEAD
will point to the previous commit. The reflog for the current branch itself will also be useful.
1Fortunately, there are few things in the world like git pull
, because git pull
is a badly-designed convenience tool that's often more inconvenient than convenient.
2Whether HEAD
is really a reference name is arguable. For reflog purposes, it is.
Upvotes: 4