1

I was working on the master branch in our git repo and merged it to our secondary branch.

Another developer who's very new to git claims he merged his changes into secondary from another branch.

When I pulled the latest changes from the secondary branch I see that all of the files and changes I committed with the merge from master are all gone now but all of his changes are there after his supposed merge. I can look back at the commits and see that his particular commit did, in fact, remove all of my changes.

He has no idea how he did this and I'm afraid to merge anything from secondary to master for fear all my changes will be lost.

What is the most likely cause and how can it be corrected so that both our changes are successfully merged instead?

eComEvo
  • 11,669
  • 26
  • 89
  • 145

2 Answers2

0

If you changed the same files, it's possible they did the merge with "ours", which takes their changes over what's in the destination branch (your changes). See git merge strategies.

Oleksi
  • 12,947
  • 4
  • 56
  • 80
  • Very few of our files were the same. Even files I newly created were completely deleted. – eComEvo May 21 '17 at 03:09
  • 1
    @eComEvo (and @Oleksi): if they used the `-s ours` *strategy* (vs the `-X ours` eXtended strategy *option*), that would ignore all the work you, eComEvo, did, while making a merge commit that links back to the commit you made. In other words `-s ours` means "kill the other guy's work entirely". – torek May 21 '17 at 03:15
  • @torek I'm really not sure. He uses the Mac app Tower, so this was probably some point and click mishap. If it was what you suggest...how do I undo it and merge both our changes? – eComEvo May 21 '17 at 03:19
  • @eComEvo you can revert his merge commit, and try it again, with the right merge options – Oleksi May 21 '17 at 03:20
  • Literally undoing a merge is easy but problematic (it's a form of "history rewriting"). See http://stackoverflow.com/questions/2389361/undo-a-git-merge-that-hasnt-been-pushed-yet?rq=1 (but this one is pushed!). Virtually undoing a merge is harder, but not actually *hard*, it's just messy. To completely re-do a merge, as if the original had never happened, see http://stackoverflow.com/q/38011005/1256452 - once you're done you can then re-integrate this result back into the branch you want it in. – torek May 21 '17 at 03:36
  • I reverted his commit that erased my changes. Now I need to step him thru merging his changes properly into the `secondary` branch. – eComEvo May 21 '17 at 03:42
0

or he did a git reset hard prior to your commits and started to make his commits? create rules in your git branch vendor or set some best practice convention like no rebasing for shared branches

letthefireflieslive
  • 11,493
  • 11
  • 37
  • 61