Is there a way to determine if a commit is cherry-picked in and which origin commit the changes cherry-picked from?
git cherry-pick -x
is a solution to record the information when I do the cherry-pick. But if we didn't use the -x
option, are there any other solutions?
git cherry-pick is a powerful command that enables arbitrary Git commits to be picked by reference and appended to the current working HEAD. 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.
git cherry-pick -n <commit> # get your patch, but don't commit (-n = --no-commit) git reset # unstage the changes from the cherry-picked commit git add -p # make all your choices (add the changes you do want) git commit # make the commit!
Even if you edit a cherry-picked commit so that the tree, the commit message, the author and committer information are exactly the same, the SHA of the parent commit (or commits, if dealing with merge commits) will be always different.
Go to either the git log or the GitHub UI and grab the unique commit hashes for each of the commits that you want. “Cherry pick” the commits you want into this branch. Run this command: git cherry-pick super-long-hash-here . That will pull just this commit into your current branch.
Git provides
git cherry
git log --cherry
both of which at a low level use git patch-id
to determine when it thinks changes have been cherry picked. Those commands will virtually never have false positives, but they may have false negatives.
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