I have two branches: A and B.
A's commit history:a <- b <- c;B's commit history:a <- h <- i;
Assume that there is only one file here.
- In commit
b, I adds some texts like "foo". - In commit
c, I adds some texts like "bar". - Then I
git cherry-pick conBbranch. I thoughtcherry-pickwill only pick the changes incto branchB. However, it will add bothfooandbarto branchB. Which is obviously not what I want.
Therefore, cherry-pick will pick all the changes of those files touched in commit c since the ancestor commit a. Is that right? What if I only want to pick the diff from b to c and apply it onto i?
Update the exact steps
- Init a git repo;
Add file
test.txtand issue the first commitinit commit.test.txtis now:first line second lineCreate a new branch
devbut stay in branchmaster;Add
added in commit bto the file and issue the commitb.test.txtis now:first line added in commit b second lineAdd
added in commit cto the file and issue the commitc.test.txtis now:first line added in commit b added in commit c second lineCheck out
devbranch and issue the commith.test.txtis now:first line second line adding by commit hgit cherry-pick <commit c SHA1 ID>to cherry-pick commitconto commith.The conflict message:
index 6a8dc57,594c6ec..0000000 @@@ -1,4 -1,4 +1,9 @@@ first line ++<<<<<<< HEAD ++======= + added in commit b + added in commit c ++>>>>>>> 06ce9b1... commit c adding another line second line + +adding by commit hSee?
cherry-pickalso brings the changed in commitb.
Thanks!