Git: Syncronizing Multiple Patches on Multiple Branches

With Openstack, I find I often have a patch up for review that I want to use as the basis for future work. When a review comes in, I have to make the changes for the review and update the commit. There are a couple ways to go about doing it, but here is one that has worked for me.I have a patch up for review right now named “Cryptographically Signed tokens” in the branch pki-tokens.   I want to use this as the basis for a patch I am calling “create-token-pullup” which will take me some time to finish. I start with

git checkout pki-tokens
git checkout -b create-tokens-pullup

and start hacking.

When I get feedback on the PKI tokens work, I commit my changes to create-tokens-pullup  and

git checkout pik-tokens.

Make the changes there, and

git commit --amend
git-review

Now my two branches are out of sync.  So,  I grab the hash of the new commit, using git log: 15b61cdef327d609c4d96c1ad8abca7650bc235c

git checkout create-tokens-pullup
git rebase -i HEAD~3

As I always go further back in history than I need, just to orient myself.

This displays a vi window like this:

1 pick b0e698a Files for  Apache-HTTPD
2 pick d64928 Cryptographically Signed tokens
3 pick 593819b apply refactoring 'Pull up method' to authenticate call in         identity providers.

Here’s the trick:  replace the hash on the second line with the new hash, so vi now shows:

1 pick b0e698a Files for  Apache-HTTPD
2 pick 15b61cd Cryptographically Signed tokens
3 pick 593819b apply refactoring 'Pull up method' to authenticate call in         identity providers.

 

Save and exit vi.  Git log now shows that HEAD~1 is the same hash as pki-tokens.

[ayoung@ayoung keystone]$ git log
commit 593819b05337bae587d26b8961e30e069282425e
Author: Adam Young 
Date:   Thu Jul 19 15:16:42 2012 -0400

    apply refactoring 'Pull up method' to authenticate call in identity provider
    
    Change-Id: Iddc95e2188179f058e0d7bf7b5c9a03cfd8fea68

commit 15b61cdef327d609c4d96c1ad8abca7650bc235c
Author: Adam Young 
Date:   Mon Jul 2 22:18:36 2012 -0400

    Cryptographically Signed tokens

4 thoughts on “Git: Syncronizing Multiple Patches on Multiple Branches

  1. Thanks for the hint to use side patch it in interactive rebase

    In this case you could also run “git rebase –onto pik-tokens create-tokens-pullup~1 create-tokens-pullup”

  2. Or just use stgi”, and do “stg rebase pik-tokens”, and see all that boring rebase/whats-the-hash work be done automatically for you.

  3. Max: OK so to translate that suggestion

    “git rebase –onto” says this is the new starting point for the rebase
    which uses the branch name pki-token to specify the commit for the rebase.

    create-tokens-pullup~1 is the old commit that is being replaced….this I don’t quite understand.

    create-tokens-pullup is the name of the branch that is being rebased.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.