Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

git rebase after git revert

While working on an open source project I encountered the following issue with git. I made a few changes, and sent a pull-request. The PR was accepted at first. However, my changes turned out to have some subtle bugs and the maintainer reverted my commits again, asking me to send a new pull-request once I've fixed the issue. However, a lot of other commits have happened in between, so I need to update my pull-request. Unfortunately, I cannot get git to rebase or cherry-pick my old PR on top of the most recent state of master.

Let me clarify things with an example. Say, my original pull-request had commits A, and B and was accepted. Then, a few commits later my PR was reverted (R), and then a few more commits happened. The history looks like this:

...--A---B--...--R--...--o master

Now, I want to transform it to the following form, in order to refine my pull-request on top of the most recent state of master:

...--A---B--...--R--...--o master
                          \
                           A---B newPR

However, I failed to achieve this with both rebase, and cherry-pick. The problem seems to be, that git thinks that A, and B are already part of master, as they are already in the history. So, it doesn't apply these changes on top of master.

How can I force git to do this?

like image 719
Lemming Avatar asked Sep 17 '25 03:09

Lemming


1 Answers

Besides the cherry-pick option, rebase now has a --force-rebase option to generate new commits so that it will ignore the previously reverted merge.

See also: the revert-a-faulty-merge How-To, git rebase --no-ff, and the full git rebase docs.

like image 105
Ari Avatar answered Sep 19 '25 19:09

Ari