So I did a local commit, went to bed. Next day, my last 7 commits disappeared. What happened?
I was able to recover the commit, but I would really like to understand what is going on. It's the first time git gives such a scare.
Git repo partial log:
* 51a1ea1 A Trace-base...
* fe62749 (fixingMess) Implemented... # <- I has here
* 498792a Finishing proposal
* 847fa4b Adding definition...
* d2ec4a6 Finishing related work
* 7c7c48a Completing proposal...
* f34274f Removed excessibe...
* d9ccd63 Chaning figs to subfigs.
* d1561db Refomulated proposal # <- Then, it jumped here
* 9e0698b Adding student automatic...
* 46a9cb1 Adding citations...
* b3e2614 Correcting references
* 078ae5f Added Proposal
* f717235 Updating ignore file
* b10811d Cosmetics.
I looked up my command history and found nothing, although I changed shells at the time and some history was lost. Here is what I have:
git status
git commit -am "Finishing related work"
git status
git commit add -am "Adding definition..."
git commit com -am "Adding definition..."
git commit -am "Adding definition..."
git push
git status
git commit -am "Finishing proposal"
git push
(commands missing)
458 git status
459 git add paper.tex
460 git commit -am "Implemented..."
504 git status
Some command ran on damage local repo.
When I do git status I receive the following message.
Your branch is up-to-date with 'origin/master'.
Result of git reflog, git reflog HEAD or git reflog master:
d1561db HEAD@{0}: commit: Refomulated proposal
9e0698b HEAD@{1}: pull: Fast-forward
b3e2614 HEAD@{2}: pull: Fast-forward
2f0d4fb HEAD@{3}: pull: Fast-forward
3a0bef4 HEAD@{4}: pull: Fast-forward
d7b0ddf HEAD@{5}: pull: Fast-forward
d96f7ae HEAD@{6}: clone: from gitolite@XXXXXXXXX:graph-moocs
Result of cat .git/HEAD:
ref: refs/heads/master
Result of 'git branch': * master
I did a new clone and the last 6 commits appear in the new folder. I did not push the last commit to the remote server, so the remote is fine.
I was able to recover my commit with git fsck --lost-found and checkout a dangling commit (after trying all the others).
What happened? How can I investigate this? (I kept a copy of the buggy local repo for investigation!)
It sounds like you might have committed in a detached HEAD state. Try git reflog master. If your commits are not there, but they are in git reflog HEAD, that is a pretty good indication.
Detached HEAD means that you checked out a commit, but not a local branch. Therefore, any commits that you do will only be referenced by HEAD. This is fine until you reset or checkout a different branch. At that point the only recourse you have is to go to your reflog which, by default, will preserve unreferenced commits for up to 30 days.
In general, it is not advisable to use a detached HEAD.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With