Reputation: 12834
A coworker and I are working on a project that uses git for source control. This afternoon, I made several commits to a particular file, MyFile.txt
. I pushed my changes to our main branch (trunk
), and my coworker merged his (unrelated) changes shortly after. Here's a visual:
After my coworker made his merge commit (the commit above tagged as 1.0.1834
), all of my changes were gone!
I switched back to my commit (tagged as 1.0.1833
) to verify that I correctly committed my changes; I did - MyFile.txt
had all of my changes from that afternoon. However, if I switch to my coworker's merge commit (tagged as 1.0.1834
), MyFile.txt
is in its original state without any of my changes.
My coworker's merge commit (1.0.1834
) contains no changes - the "Diff" window in gitk
is empty. Here's another view of the commit from our GitLab site:
What happened? Where did my changes go? How can I prevent this from happening in the future?
Upvotes: 1
Views: 236
Reputation: 1329742
That could happen if your cowroker has done a git merge --ours
.
The resulting merge commit would be identical to his previous commit HEAD.
This is the merge strategy ours:
the resulting tree of the merge is always that of the current branch head, effectively ignoring all changes from all other branches. It is meant to be used to supersede old development history of side branches.
Note that this is different from the-Xours
option to the recursive merge strategy.
Upvotes: 1