1

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

matthesinator
  • 136
  • 1
  • 8
  • Do you really have two branches or just two open changes based on each other? If you really have two branches, are there open changes for each one? – Marcelo Ávila de Oliveira Jul 20 '20 at 15:09
  • @MarceloÁviladeOliveira There are two branches and two changes. I keep one branch per change. Don't know if that's best practice for Gerrit but so far it has mostly worked. Apart from the rebasing thing – matthesinator Jul 20 '20 at 15:37

2 Answers2

1

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
LeGEC
  • 46,477
  • 5
  • 57
  • 104
1

The correct solution is option 1 (git checkout B; git rebase A). I can't imagine why the new commit would receive the Change-Id of A. Try to repeat the procedure to see if you're able to reproduce the issue. If the issue happens again you just need to execute "git commit --amend", change the Change-Id (from A to B) and then execute the "git push".