If I cherry-pick a commit which makes no changes, but I want it to commit anyways (so that the audit trail of commits is consistent with another project), I get the message:
$ git cherry-pick 696abcb
...
nothing to commit, working directory clean
The previous cherry-pick is now empty, possibly due to conflict resolution.
If you wish to commit it anyway, use:
git commit --allow-empty
According to the man pages, I can use cherry-pick with --allow-empty
. But this results in the same message:
$ git cherry-pick --allow-empty 696abcb
(same message as above)
Is this a bug? Am I completely misunderstanding the point of this option?
It's exactly what it says: the changes you're trying to cherry-pick are already wholly contained in the branch you're on. I.e. the result of the cherry-pick is no changes. You can create an empty commit with the --allow-empty flag to indicate that you attempted to cherry-pick, but there were no changes to pull in.
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.
One possible way to avoid these cherry-pick conflicts is by doing the cherry-picking in the order of oldest commit to latest commit, i.e. based on commit date.
The git cherry-pick is a very useful command. It takes changes from a specific commit and applies them to your current branch in a new commit. As a consequence, git cherry pick does not alter your current Git history : instead it adds commits to it.
With Git 2.22 (Q2 2019), you won't have to run git commit --allow-empty
.
"git cherry-pick --options A..B
", after giving control back to the user to ask help resolving a conflicted step, did not honor the options it originally received, which has been corrected.
See commit 6860ce5, commit 36b0503, commit f59199d (13 Mar 2019) by Phillip Wood (phillipwood
).
(Merged by Junio C Hamano -- gitster
-- in commit d2dba18, 25 Apr 2019)
cherry-pick --continue
: remember optionsRemember
--allow-empty
,--allow-empty-message
and--keep-redundant-commits
when cherry-pick stops for a conflict resolution.
Since there's nothing to cherry-pick, there's no work that can be done. The only possible thing that you could do is create an empty commit. It's not instructing you to run git cherry-pick --allow-empty
, instead it's instructing you to run:
git commit --allow-empty
Note that's the commit command. git will not, by default, create commits with no changes in them.
(git questions the value of creating an empty commit, just to include a commit message in your history - as do I, to be frank - but if you need it for auditing, then this is the way to do it.)
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