Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>If you have not yet garbage collected your repository (e.g. using <code>git repack -d</code> or <code>git gc</code>, but note that garbage collection can also happen automatically), then your commit is still there – it's just no longer reachable through the HEAD.</p> <p>You can try to find your commit by looking through the output of <code>git fsck --lost-found</code>.</p> <p>Newer versions of Git have something called the "reflog", which is a log of all changes that are made to the refs (as opposed to changes that are made to the repository contents). So, for example, every time you switch your HEAD (i.e. every time you do a <code>git checkout</code> to switch branches) that will be logged. And, of course, your <code>git reset</code> also manipulated the HEAD, so it was also logged. You can access older states of your refs in a similar way that you can access older states of your repository, by using an <code>@</code> sign instead of a <code>~</code>, like <code>git reset HEAD@{1}</code>.</p> <p>It took me a while to understand what the difference is between HEAD@{1} and HEAD~1, so here is a little explanation:</p> <pre><code>git init git commit --allow-empty -mOne git commit --allow-empty -mTwo git checkout -b anotherbranch git commit --allow-empty -mThree git checkout master # This changes the HEAD, but not the repository contents git show HEAD~1 # =&gt; One git show HEAD@{1} # =&gt; Three git reflog </code></pre> <p>So, <code>HEAD~1</code> means "go to the commit before the commit that HEAD currently points at", while <code>HEAD@{1}</code> means "go to the commit that HEAD pointed at before it pointed at where it currently points at".</p> <p>That will easily allow you to find your lost commit and recover it.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload