2

We have this git log:

D:\blah>git log -n 5 --oneline    
fc19dec My change #2
68fa9db Merge branch 
4bc1ac7 My change #1
ec345d9 [maven-release-plugin] prepare for next development iteration

I'd like to revert to ec345d9 but am getting an error:

D:\blah>git revert --no-commit ec345d9..HEAD
error: a cherry-pick or revert is already in progress
hint: try "git cherry-pick (--continue | --quit | --abort)"
fatal: revert failed

How can I do this revert?

I am aware of the issue with reverting a merge and needing to specify the -m option. When I've used that in the past I am just reverting the one single merge commit. But in this case the merge commit is sandwiched between two other commits I'm trying to revert.

Marcus Leon
  • 55,199
  • 118
  • 297
  • 429
  • Have you tried aborting the cherry-pick that you're abandoning? – Paul Hicks Nov 06 '17 at 23:55
  • Are you sure you want to revert? Since there are no commits after ec345d9 that you want to keep, wouldn't checkout / move master be easier? "revert" creates new commits with the opposite of the reverted commits: it rolls _forward_ to the old state. checkout / branch -d master / branch master (or whatever branch you're on) simply rolls _back_ the branch to the desired commit and leaves the other commits dangling. They'll go away the next time you gc. – Paul Hicks Nov 06 '17 at 23:57

1 Answers1

2

First, make sure that your merge does not include the changes from the commit below it, when you specify the -m 1 (or other mainline number) option.

(Well, first first, finish or abort the cherry-pick or revert you're in the middle of now. Then check whether the merge includes one of those commits' changes.)

Now that you're sure which commits to revert, and which ones need a -m option and which ones require not using a -m option, do them one at a time, most-recent first:

git revert fc19dec
git revert -m 1 68fa9db
git revert 4bc1ac7

for instance. Note that this produces three separate new commits, each one doing one revert. (This is what you would get with the .. notation as well.) If you want to get one big revert commit, use git revert -n each time, and commit the final result separately once done.

torek
  • 448,244
  • 59
  • 642
  • 775
  • In the end I realized I didn't need to revert the merge so I just did the first and third reverts and it worked properly. Thanks. – Marcus Leon Nov 07 '17 at 14:42