I am cherry picking a commit from branch A into branch B. Branch A is many commits ahead of branch B, and I wanted to ignore a few previous commits in branch A and cherry-pick a future commit. For example, branch A has commits 1,2,3,4,5,6 and branch B has just 1,2 and I wanted to cherry-pick commit 6 from branch A into branch B. Turns out I did not realize that commit 6 changes a file introduced in commit 5(which branch B does not have). But on trying the cherry-pick of 6(to branch B), git did not show the file introduced in commit 5 as a conflict. I just lost the changes made in that file when I cherry-picked commit 6. Was that expected? Am I doing it wrong?
The command I ran was just "git cherry-pick <commit-id>"
Since the commit 6 has the path/file src/test/resources/RefreshedJarClassV2.txt which is not exist on branch B, when you cherry-pick commit 6 to branch B. there will show unmerged paths and you should mark this path to current working directory. Details steps as below:
If you have already cherry-pick commit 6 on branch B as below graph,
1---2---6' Branch B
\
3---4---5---6 Branch A
you should reset branch B as the original by:
git checkout B
git reset --hard <commit id for 2>
Then the branch structure will looks like the original:
1---2 Branch B
\
3---4---5---6 Branch A
Now cherry-pick commit 6 again:
git cherry-pick <commit id for 6>
git add .
git cherry-pick --continue
And the path and file src/test/resources/RefreshedJarClassV2.txt will show in branch B.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With