Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

git cherry-pick not working

People also ask

How do I use git cherry pick?

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.

Why is cherry pick empty?

If a commit being cherry picked duplicates a commit already in the current history, it will become empty. By default these redundant commits cause cherry-pick to stop so the user can examine the commit. This option overrides that behavior and creates an empty commit object. Implies --allow-empty .

Should I use git cherry pick?

git cherry-pick is a simple but powerful tool that allows you to selectively transfer commits from one branch to another. You can use it when you don't want to merge an entire branch into master, but would still like to include changes from a feature branch.


Git is resolving the cherry-pick as a no-op -- all of the changes introduced by that commit have been introduced by some commit on your current branch. (Or that's what Git thinks, anyway.) Verify that the commit you are cherry-picking hasn't already been merged somehow, as either a proper merge, rebase/cherry-pick, or piecemeal patch. (Use git show <commit-id> to see the diff.)


In my case this was driving me nuts, as it was quite obvious that the specific commit I wanted to cherry pick had not been merged into my current branch.

It turns out someone had already cherry picked the commit a week prior. The changes, but not the specific SHA, were already in my current branch, and I had not noticed them.

Check the file(s) that you're attempting to cherry pick. If they already have the changes, a version of the commit has already been cherry picked or added in another manner. There is thus no need to cherry pick it again.


Also note that adding an empty file (e.g. .gitkeep) to the tree is considered by cherry-pick as an empty commit.


So, here's Yet Another Confusing Situation where this can arise: I had the following:

git log screenshot

I was trying to cherry pick 9a7b12e which is apparently nothing--it even tried to tell me on that line in the git log output that 4497428 was what I really wanted. (What I did was just looked for the commit message and grabbed the first hash I saw that had it). Anyway, just wanting to let people know that there's another way you can get tricked into trying to cherry pick a no op.


One more possible reason of this error happening is the sequence of commits passed to git cherry-pick. You must select the first commit as the Start commit and then move forward in time.

I had the same problem, in my case commit history was as below,

   Commit Sequence   976e364---2b162b6---x...etc

I ran below which produced the same error/issue as the question,

git cherry-pick 2b162b6 976e364   //this is wrong commit sequence 

underlying issue above case is the commit sequence.

git cherry-pick 976e364 2b162b6   //this is correct commit sequence

In the git official documentation it states as

Note: Commit Sequence matters indeed.

# Find the range of commits you wish to re-add to your branch.
# then use cherry-pick to add them back to the branch
git cherry-pick start..end

# If you wish to include the start commit as well add the ^
# This will result in a cherry-pick of the start commit included as well 
git cherry-pick start^..end