Why would my commit of a file be missing from the git history

Go To StackoverFlow.com

1

So I was working on a file and committed it to my tracking branch and pushed up to the remote branch. Someone else must have made a change to the same file and had a conflict with my change and they resolved the issue, but removed my edits as the resolve. There was an error when they went to the application the next time and realized it was with something I was working on.

I tried to view the history of the file but it had appeared that my commit was removed from the history. The people working on the project are not doing any advanced git techniques, its pretty much fetch merge, commit push.

I just don't get why the commit is gone from my history. Shouldn't it be there or when there is a merge conflict and someone resolves and ends up doing a merge commit does that remove history?

We host our repo on bitbucket and I can go there and find my commit with the code I needed to update the file but this seems less then ideal.

We are all new at git and using it for the first time on one of our projects so we are pretty nubish at all this.

2012-04-04 17:16
by dan.codes
Where did you look to review history? are you using EGit, native git, gitweb, or some other tool - Jason Huntley 2012-04-04 17:19
As long as someone didn't do something destructive like a rebase and then did a force push, your commit should still be there somewhere - Abe Voelker 2012-04-04 17:20
I use phpstorm as an IDE. I don't see it in there when doing a show history on the file. I also did it on the command line git log -p filenamedan.codes 2012-04-04 17:46
@Abe Voelker interesting. I don't think anyone did a rebase. All we have been doing is using phpstorm which is like inteillij idea but for php. In there I have been having people just fetch and merge - dan.codes 2012-04-04 17:47
If it hasn't been long since this happened (like within the last month), you should be able to use a combination of git reflog and git fsck --lost-found to be able to find your lost commits. Git will never throw away your history without asking you, and even then keeps the references around for awhile before they get garbage collected. It might take some searching but you should be able to get your commits back - Abe Voelker 2012-04-04 18:15
@AbeVoelker I don't really need it, it was something pretty simple my only concern is if this happens again and I don't know about it at the time I might not know where the commit should have been. Should there be a way to see how it got removed. I am more concerned with how this happened then actually fixing it - dan.codes 2012-04-04 18:21
I can see it when doing the reflog, what does that mean? Why can't I see it in the log or in my GUI for show history - dan.codes 2012-04-04 18:24


3

Git's internal structure is that of a DAG, and the branches are just mutable pointers to commits (tags are immutable pointers). Git's log only shows you commits that are reachable by backtracking off of these branches / commit pointers. Somehow, the branch pointer(s) got changed so that your commit became unreachable by backtracking. Something destructive happened in order to cause this, like a rebase.

Since you found your commit, you can see where it fits into the tree by doing this:

git checkout -b temp_branch
git reset --hard <lost-commit-sha1>
gitk --all

temp_branch is now pointing at your commit and you can see what happened by looking at the DAG.

2012-04-04 18:49
by Abe Voelker


1

To answer your question: Someone rewrote the branch history. There's no other way to lose pushed commits.

Solutions to avoid this: restrict non-fast-forward push to most developers and training.

2012-04-04 18:47
by KurzedMetal
Ads