Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why does `git cherry-pick --allow-empty` have no effect?

Tags:

git

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?

like image 902
Otheus Avatar asked May 26 '18 07:05

Otheus


People also ask

Why is cherry pick commit empty?

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.

How does cherry pick work in git?

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.

How do you fix cherry pick conflict?

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.

Does cherry pick creates new commit?

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.


2 Answers

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 options

Remember --allow-empty, --allow-empty-message and --keep-redundant-commits when cherry-pick stops for a conflict resolution.

like image 176
VonC Avatar answered Oct 20 '22 20:10

VonC


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.)

like image 44
Edward Thomson Avatar answered Oct 20 '22 20:10

Edward Thomson