Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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 ?

like image 408
Ashutosh Jindal Avatar asked Jul 31 '12 10:07

Ashutosh Jindal


People also ask

Does rebase use cherry pick?

In fact, cherry picks can even be used to replace rebases.

How do I update my cherry pick?

Change commit message when cherry-picking As a consequence, you may want to change the commit message when cherry-picking. To change the commit message when cherry-picking, use “git cherry-pick” with the “-e” option.


1 Answers

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.

like image 168
thameera Avatar answered Sep 28 '22 10:09

thameera