Ashutosh Jindal
Ashutosh Jindal

Reputation: 18869

How to rebase on a new version of a cherry picked parent

Consider the highlighted commits in the following :

GITK

For the current discussion I'll refer to the commits as follows : Commit 1 : Read Language settings from the User Settings Commit 2 : [POC] Do not review

We use Gerrit for code review. Both Commit 1 and Commit 2 are under review and have not been merged. I am working on Commit 1 which required code in Commit 2 and hence had to be based off it. These are the commands I used :

  1. Cherry Pick Commit 2. I use the cherry-pick command that get from Gerrit for that change: Cherry-pick Commit 2

  2. Make the changes that were needed for my work and push a change which became Commit 1. When I first pushed Commit 1, it was based on patchset 8 of Commit 2.

As and when I get review comments on my commit (Commit 1), I push new patch sets for it on Gerrit. However, when it is to be merged finally, it needs to be on the latest patchset of it's parent (Commit 2). The way I do it now is as follows :

  1. git checkout working2
  2. git reset --hard remotes/origin/head
  3. Cherry-pick Commit 2 ---> This gets me the latest version of Commit 2
  4. Cherry-pick Commit 1
  5. git push origin working2:refs/for/head

Is there a way in which I can just get the latest patchset of Commit 2 without doing all of the above ? Perhaps some kind of interactive cherry pick or rebase ?

Upvotes: 6

Views: 7032

Answers (1)

thameera
thameera

Reputation: 9473

You can simply rebase Commit 1 to the FETCH_HEAD. While on working2 branch,

$ git fetch ssh://[email protected]:29418/management-console refs/changes/26/11926/11 
$ git rebase -i FETCH_HEAD

Remove the line with the commit message of Commit 2 (first line usually). Now Commit 1 will be on top of the latest Commit 2. If you're unfamiliar with interactive rebase, take a look here.

Upvotes: 8

Related Questions