Reputation: 1244
I Have the following situation I have the file example.txt
line A
I have the commit 1 that added this line
than on commit 2 I change the line
line A B
I did the commit 2 and I pushed that.
when downloading the branch and looking at the file you can only see
line A
if you do
git log -- example.txt
I got
commit 1
but if I do
git log
I got
commit 2
commit 1
Does anyone know what can be happening ? and how can I get more diagnostics or even better fix this?
Just to complete some info I'm on master branch and this commit it is on the log of the master branch.
Upvotes: 0
Views: 51
Reputation: 19025
This is most likely because someone else on your team botched a merge. Here is a scenario that would replicate what you are seeing:
At this point, person X gets conflicts, so the automatic merge commit that usually happens during a pull does not get performed. Person X then notices that there are local changes on his machine that he did not make - specifically, your change in commit 2 to example.txt. He discards those changes, commits, and pushes. So your change never gets merged in, and example.txt only contains "line A".
So, why is commit 2 not showing when one does a log of the file? The reason comes down to what commits git decides should be included in a file's history. Git walks the tree, and (by default) when it hits a commit where example.txt has not changed with one of its parents, it continues its search with that parent, ignoring the other one. So when it hits the merge that person X did, it ignores the parent where example.txt is different, i.e. it ignores the path that contains commit 2. You can verify this by passing --full-history
to git log
, which changes the default behavior so that both parents are followed. If you do that, you should see commit 2.
The moral of the story is that when you have merge conflicts and you see local changes you did not make, you must commit those changes along with your own. Otherwise you will run into this situation again.
Upvotes: 1