The last 7 Git commit disappeared and the head stepped back
So I did a local commit, went to bed. The next day, my last 7 commits were gone. What happened?
I was able to restore the commit, but I'd love to understand what's going on. This is the first time git has given such fear.
Git incomplete log repo:
* 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 through the history of my team and did not find anything, although at that time I changed the shells and some history was lost. Here's 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
(no commands)
458 git status
459 git add paper.tex
460 git commit -am "Implemented..."
504 git status
Some command was run when local repo got corrupted.
When I do git status
, I get the following message.
Your branch has been updated with "origin / master".
Result 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 cat .git/HEAD
: ref: refs / heads / master
Result of 'git branch': * master
I made a new clone and the last 6 commits will appear in the new folder. I haven't pushed the last commit to the remote server, so the remote sound is fine.
I was able to restore my commit with git fsck --lost-found
and a checkout
hovered commit (after trying everyone else).
What happened? How can I investigate this? (I kept a buggy copy of the local repo for investigation!)
source to share
It sounds like you did it in a separate HEAD state. Try it git reflog master
. If your commits aren't there, but they're in git reflog HEAD
, that's a pretty good sign.
A separate HEAD means you checked out a commit, but not a local branch. Therefore, any commits you make will only refer to HEAD. This is fine as long as you reset or check out another branch. At this point, you only need to refer to your reflog, which will save unrecorded commits by default for up to 30 days.
In general, it is not recommended to use a separate head.
source to share