I have several git branches that have commits cherry-picked between them. Commits are sometimes squashed.
In order to decide whether to apply a commit abcdef
to the live
branch, I want to find out if an equivalent commit has already been applied to the preprod
branch.
If preprod
never squashed commits, I would use patch IDs, as discussed in this question. Since preprod
may squash sequences of commits, I want to see if abcdef
would be an empty commit on preprod
.
$ git checkout preprod
$ git cherry-pick abcdef
On branch preprod
Your branch is up-to-date with 'origin/preprod'.
You are currently cherry-picking commit abcdef.
The previous cherry-pick is now empty, possibly due to conflict resolution.
If you wish to commit it anyway, use:
git commit --allow-empty
Otherwise, please use 'git reset'
How can I programmatically detect if cherry-picking a commit would result in an empty commit?
(I know this is an imperfect heuristic for detecting whether the patch has been applied, but it's good enough for my use case.)
In order to create Git patch file for a specific commit, use the “git format-patch” command with the “-1” option and the commit SHA. In order to get the commit SHA, you have to use the “git log” command and look for the corresponding commit SHA.
Sometimes people run diff with the new file first instead of second. This creates a diff that is “reversed”. To apply such patches, give patch the --reverse ( -R ) option. patch then attempts to swap each hunk around before applying it.
A patch is a text file whose contents are similar to Git diff but along with code it contains metadata about commits, for example, a patch file will include commit ID, date, commit message, etc. We can create a patch from commits and other people can apply them to their repository.
Take a look at git cherry
:
Find commits yet to be applied to upstream
Something like this should do the trick by displaying commit abcdef
if a cherry-pick is necessary else nothing (didn't check):
git cherry abcdef preprod abcdef^
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