I cherry-picked
a commit and resolved the conflicts, added them, now when I try to do git amend it fails with below message.
fatal: You are in the middle of a cherry-pick -- cannot amend.
Why does git gives this message, is there a way to tell it things are fine?
cherry-pick effectively applies the changes from commit A onto the working tree and makes a commit. This means if you get any conflicts during cherry-pick ing you need to commit after resolving them to finish the cherry-pick . EDIT Edward noted that this is only true when you are cherry-pick ing a single commit.
A cherry-pick is basically a commit, so if you want to undo it, you just undo the commit. Stash your current changes so you can reapply them after resetting the commit.
Try also with '--quit' option, which allows you to abort the current operation and further clear the sequencer state. --quit Forget about the current operation in progress. Can be used to clear the sequencer state after a failed cherry-pick or revert.
I manually removed .git/CHERRY_PICK_HEAD
now git doesn't know I did a cherry-pick, so amend works like it was a normal commit amend.
cherry-pick --continue
adds a new commit message and would need to rebase which is a hassle.
It seems that you did a cherry-pick
before, which failed due to conflicts. Thus, git thinks you're still in the middle of the cherry pick, since it expects you to fix conflicts, add conflicted files and run git cherry-pick --continue
.
Your options here are to run git cherry-pick --abort
which will abort the cherry pick, i.e. return the conflicted files to their previous state, possible losing changes, or to run git cherry-pick --continue
, which will continue the cherry pick. When you do not remember when and what you did with the cherry-pick, this is probably the better option, althoough you should watch your repository closely before and after the --continue
command.
Both commands will get you out of the cherry-pick state and allow you to perform the amend.
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