So I'm trying to understand why when I git merge master
into a branch, I lose some, but not all of my changes in a commit. It seems to do with a cherry-pick commit on my branch. Here's how to reproduce:
- init a repo with an initial commit
- Add a line of text to a file and commit
- Branch off this, call it "test"
- On branch master, revert the second commit
- Cherry-pick that commit into the test branch
- Go back to master, create a new commit that restores that line of text, plus add additional changes
- Go back to test, run
git merge master
- Notice that the merge automatically removed that line of text (!!!), but kept the additional changes. I expect the merge to not drop that line, so that it matches
master
.
I uploaded my results on github: https://github.com/terryttsai/testRevertMerge/commits/test
If I never cherry-picked that commit into my test
branch, then git merge master
does keep that line of text. So how come when I do have that cherry-pick commit, the merge removes it? How can I prevent this from happening in the first place?