0

I cherry picked a commit, from two years ago and fixed the conflicts (as well as committing the change), but when I try and cherry pick a commit from five months ago:

$: git cherry-pick 9f73972f3f619f1357269493e01f07c500d61ed9 On branch get_ndt_up_to_staging_branch You are currently cherry-picking commit 9f73972. nothing to commit, working tree 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 Otherwise, please use 'git reset' 

How is that true? When I look on github, the commit in question has changes to various files.

Am I doing something wrong?

Edit:

When I fixed all conflicts I committed them and attempted to do cherry-pick --continue and it gave me the same error. Did I do cherry pick wrong?

2 Answers 2

4

Typically you get this error if the changes in the commit are already in the current version of the code. In that case, git decides that the cherry-pick would result in a commit that makes no changes, so it asks whether you want to allow an empty commit with --allow-empty.

If you fixed conflicts and the result of the resolution again matches with the current state of the working tree and current HEAD, then you will get the same error.

I'd recommend taking a close look with git show 9f73972 and compare with the current state of your working tree and repository.

Sign up to request clarification or add additional context in comments.

2 Comments

There are changes, tons of them. They create conflicts when merged in. So I fix the conflicts to make it up to-date with our branch (mostly taking theirs as its a commit I need). But then theres commits after that, such as: 9f73972 that I need as well. So I am lost ...
@TheWebs, When you cherry-pick a commit, you cherry-pick only the changes in introduced in that commit. If you've fixed the conflicts in a way that makes the state look exactly like your current repo, the there was no need to cherry-pick that commit. Maybe you want to cherry-pick the commits after it instead.
-1

It sounds like the result of fixing the conflicts is that there is no need to take the commit.

Consider, for instance, a commit that consists of a one-word spelling fix:

--- a/text.txt +++ b/text.txt @@ -nn,1 +nn,1 @@ some context is here -and there was a tyop +and there was a typo in one of the lines 

Suppose you decide to cherry-pick this commit. In your current (HEAD) commit, this same file has:

some context is here but there are no typos in one of the lines 

The cherry-pick operation will tell you that there is a conflict between the change you are cherry-picking (which tries to change "tyop" to "typo" in that line) with the version that you are actually using (which does not have that line at all).

When you look at the file and think about it, you will probably choose to use the latest line, which has no typo to fix. The effect of applying the typo fix, then, is to make no changes to the source.

When you run git cherry-pick --continue, Git will tell you that you made no changes. You must now decide:

  • Did you resolve all the conflicts correctly, or did you accidentally resolve the conflict by dropping a change that you wanted to keep?
  • If you did resolve all the conflicts correctly, do you want to make a new commit whose files are all 100% identical to the original commits? If so, use git commit --allow-empty.
  • If you don't need any of the changes after all, use git cherry-pick --abort (to end the operation entirely). This is also spelled git reset (I prefer the git cherry-pick --abort spelling).

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.