For example, I have a dev
branch and a stable
branch.
In case I have cherry-picked several commit from dev
to stable
.
Is there any way to let Git aware of the cherry-picked commits, and avoid doubly-merging it if I later merge, rebase or cherry-pick an overlapped range, from dev
back to stable
? (for which is a basic merge tracking feature in SVN)
With the cherry-pick command, Git lets you incorporate selected individual commits from any branch into your current Git HEAD branch. When performing a git merge or git rebase , all the commits from a branch are combined. The cherry-pick command allows you to select individual commits for integration.
You can cherry-pick merge requests from the same project, or forks of the same project, from the GitLab user interface: In the merge request's secondary menu, select Commits to display the commit details page. Select the Options dropdown and select Cherry-pick to show the cherry-pick modal.
Cherry picking is the act of picking a commit from a branch and applying it to another. git cherry-pick can be useful for undoing changes. For example, say a commit is accidently made to the wrong branch. You can switch to the correct branch and cherry-pick the commit to where it should belong.
Also notable is that -x
flag for cherry-pick
adds the SHA of the original commit to the end of the commit message.
I like to add the abbreviated SHA to the end of the commit summary, too, to make it easier to associate the cherry-picked commit with the original when looking at the log. Indicating who did the cherry pick can be helpful too, with the -s
signoff flag.
Example:
> git cherry-pick -sex 27d4985
#333: fixes all the things (27d4985) - how it fixes all the things (cherry picked from commit 27d49855238364d0184ad344884a366b5b16e) Signed-off-by: Chuck Norris <[email protected]>
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