Search code examples
gitmergecommitgerritrebase

Git update branch after changing parent


I currently have a few branches that are based on each other. We're also using Gerrit.

master
    \- A
        \- B

There are actually four in total but to explain my problem two should suffice. My problem is as follows: I've made changes to A and want to get those changes in B. What I've tried:

  1. git checkout B && git rebase A
  2. git checkout B && git merge A

Problem with 1.):

The rebase itself worked fine, but somehow it creates a commit with the Change-Id of A, so if I push after rebasing, the change A gets an empty patchset. I think one time I even f-ed up some files. Manually deleting that commit works, but there is a better way, right?

Problem with 2.):

The merge itself works, again, fine. But I can't git commit --amend to update B, I need to do git commit, which creates a new commit, which I don't want and need. After that I need to copy the old commit message to the new commit. This works, but I don't think that's the way it is supposed to be done?

So, how can I get the updates from A in B and simply use git commit --amend to update the commit message and then push it to gerrit? Thank you!

Edit: This helped a lot


Solution

  • To rebase B on A in this case, you would need to pass extra arguments to git rebase :

    git rebase --onto A <previous A sha> B