简体   繁体   中英

How do I upgrade branch to lastest of an old Gerrit commit

I have three dependant Gerrit commits that require some changes before they will get merged into master branch.

  • Commit A
  • Commit B (depends on A)
  • Commit C (depends on B)

The problem is that my master has significantly changed since these three commits were added. I suspect I should update base on which these three commits are based upon and then do the changes and amend them, but I'm not sure whether that's the actual scenario I should be doing?

I wanted to do the changes one by one from A to C and committing back. I did Download > Checkout > Copy to bash to get to detached HEAD of commit A but when I try to run it I get many errors I didn't used to have them when I committed this code.

I'm not sure what I should be actually doing to add these changes to all three individually and then merge together to base branch.

Why is this important? Because my code is calling some backend service which has changes some types and the new master has new types defined properly while my outdated Gerrit commits still use the old types with invalid properties etc.

What I'd actually like to do? I guess what I actually want to do it to change base of my three commits to be based on latest master and not some old master commit. Or maybe I just misunderstand what I should actually be doing.

Edit

I've tried something and I wonder whether this is one of the possible ways? It surely seems that it puts my Commit A on top of current master HEAD:

git checkout master
// we're mostly rebasing
git pull origin --rebase
// copied command from gerrit
git fetch ... && git checkout FETCH_HEAD
git rebase master

After I add a patch to Commit A I should likely do the same steps for B and C commits as well.

Seems that types are now updated and that I can update detached head. I haven't amended my commit though as I would like some sort of confirmation that this will do what I intend to do.

Do the following.

  1. git fetch

CommitA

  1. git checkout -b branch_a CommitA
  2. git rebase origin/master
  3. Resolve conflicts
  4. git commit --amend
  5. git push origin branch_a:master

CommitB

  1. git checkout -b branch_b CommitB
  2. git rebase branch_a
  3. Resolve conflicts
  4. git commit --amend
  5. git push origin branch_b:master

CommitC

  1. git checkout -b branch_c CommitC
  2. git rebase branch_b
  3. Resolve conflicts
  4. git commit --amend
  5. git push origin branch_c:master

Note1: You can try to do the procedure using the "Rebase" button on Gerrit UI, but this will not work if you have conflicts.

Note2: You can remove the branch_ branches at the end of the procedure. They're not really neeeded after all, everything will work pretty well if you use just the correct commit IDs instead.

Note3: Avoid to work this way. Try to not push commits to Gerrit based on non-integrated (reviewed/approved/submitted) commits. Always try to work with "parallel" commits.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM