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:
git merge master
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?
I expect the merge to not drop that line, so that it matches master.
No. git merge master
does not mean to match master!
What is a merge? A merge means to play out the contributions of branches, starting from the point of divergence.分支的贡献。 What are they?
Well, the point of divergence is after that first line was added. So what happened after that on each branch?
On master, the only contribution is the extra stuff. (It removed the first line but later restored it, so that is not a contribution; in that respect nothing happened at all.)
On test, the only contribution is deletion of the first line (that is what the cherry picked revert commit does).
So the merge does both of them: the extra lines from master, and the deletion from test.
But if you never do the cherry pick, then neither branch makes a contribution that deletes that line, so obviously it is not deleted by the merge.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.