Git rebase after git revert

While working on an open source project, I ran into the following problem: git. I made a few changes and submitted a pull request. PR was adopted first. However, there were some subtle bugs in my changes and the maintainer reverted my commits again, asking me to submit a new pull request as soon as I fixed the issue. However, many other commits happened in between, so I need to update the pull request. Unfortunately I can't get git to reinstall or cherry-pick my old PR on top of the most recent state master

.

Let me clarify the situation with an example. Let's say my initial pull request made A

and B

and was accepted. Then, a little later, my PR got canceled ( R

) and then a few more commits happened. The story looks like this:

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

      

Now I want to convert it to the following form to refine my upload request on top of the most recent state master

:

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

      

However, I was unable to achieve this with rebase

and cherry-pick

. The problem seems to be that git thinks that A

and B

are already a part master

as they are already in history. Therefore, these changes do not apply to master

.

How can I get git to do this?

+3


source to share


2 answers


In addition to the cherry-pick option, rebase now has an option --force-rebase

to generate new commits so that it ignores the previously returned merge.



See also: revert-a-faulty-merge How-To , git rebase --no-ff

and complete git rebase

.

+2


source


Edited

git checkout master
git checkout -b redo
git cherry-pick Aref
git cherry-pick Bref
... do fixes and commits
git merge master

      

Before

* e553928d35646512f640b0f0ca208f6729884993 D
* 5157867afdbdcf4300f7b722e3816e294e0f2ae4 C
* caa01fd5378f87b67811212aa4325963fab72905 Revert "A"
* 8603f6b1231dbefa4911699cb59fa81f1a20e432 Revert "B"
* d4c38c2c63ab0b4be00480bf9c9542ffc66dcb5f B
* f2f6e0a0b7a804a4a8075839d7b73b37b747a7b3 A
* 59597e64b49b234b45a94a86d950f0811a19cdfe root commit

      



After

* e6a314b66d8be8a85abd6becd53e0d2c7a6332a5 E
* d7d91af4225d5ba7d783303e73bcac1b5ba02a91 B
* 381b95bea7f87662f72a1da67bd70cdfc497be47 A
* e553928d35646512f640b0f0ca208f6729884993 D
* 5157867afdbdcf4300f7b722e3816e294e0f2ae4 C
* caa01fd5378f87b67811212aa4325963fab72905 Revert "A"
* 8603f6b1231dbefa4911699cb59fa81f1a20e432 Revert "B"
* d4c38c2c63ab0b4be00480bf9c9542ffc66dcb5f B
* f2f6e0a0b7a804a4a8075839d7b73b37b747a7b3 A
* 59597e64b49b234b45a94a86d950f0811a19cdfe root commit

      

Works for me locally

$ git checkout master
Switched to branch 'master'
$ ls
A B C D E

      

0


source







All Articles