1

I made one commit containing multiple files and pushed it into Gerrit for a code review. This is HEAD~1.

Then I made another commit, also containing multiple files and pushed it into Gerrit for another code review. This is HEAD.

Now I realized I need to make a correction to one file for the commit HEAD~1 but that file was also changed within the more recent HEAD commit.

Do I need to make the change to the file for HEAD~1 without the changes in HEAD, commit it, rebase/squash that commit into the HEAD~1 commit and push it into the same change in Gerrit, and then do the same for the HEAD commit?

amphibient
  • 29,770
  • 54
  • 146
  • 240

2 Answers2

2

First you need to move your changes to branches: This is for example your original log

#git log --graph --decorate --oneline -n13
* e40f865 (HEAD, master) Change 2
* 120c061 Change 1
* 73a8f97 Initial commit

Now move them into a branch:

#git branch changeA 120c061
#git branch changeB e40f865
#git log --graph --decorate --oneline -n13
* e40f865 (HEAD, master, changeB) Change 2
* 120c061 (changeA) Change 1
* 73a8f97 Initial commit

As you can see, changeB depends on changeA. Now reset the master so the changes are not in the master but really in the branch:

#git reset --hard HEAD~2
HEAD is now at 73a8f97 Initial commit

Now, checkout changeA and make you change. The amended commit:

#git commit --amend -a
[changeA 93837a4] Change 1
 2 files changed, 3 insertions(+), 2 deletions(-)
#git log --graph --decorate --oneline -n13
* 93837a4 (HEAD, changeA) Change 1
* 73a8f97 (master) Initial commit

As you see the change 1 has a new SHA1, next checkout changeB:

#git checkout changeB
Switched to branch 'changeB'
#git log --graph --decorate --oneline -n13
* e40f865 (HEAD, changeB) Change 2
* 120c061 Change 1
* 73a8f97 (master) Initial commit

Now you see that changeB still depends on the original change 1, you just need to rebase the change to the new change 1.

#git rebase 93837a4
First, rewinding head to replay your work on top of it...
Applying: Change 1
Using index info to reconstruct a base tree...
....
....
Applying: Change 2

#git log --graph --decorate --oneline -n13
* d3fac58 (HEAD, changeB) Change 2
* 93837a4 (changeA) Change 1
* 73a8f97 (master) Initial commit

And now you have the updated changeB that depends on the update changeB and you can submit it again to Gerrit for review

uncletall
  • 6,609
  • 1
  • 27
  • 52
  • 1
    That seems more detailed than my answer. +1 – VonC Nov 11 '13 at 07:12
  • when i pushed the rebased changed into Gerrit, it made a whole new code review item but i wanted it to amend the existing one. Is there a way to do it? – amphibient Nov 11 '13 at 22:08
  • I assume you have the ChangeID in your commit messages? Did you then use the --amend to amend your commit? Just check if the changeid's have not changed. – uncletall Nov 12 '13 at 00:56
1

Yes: as explained in "How to amend review issues in Gerrit when there is a second newer review also"

When you have dependent reviews in Gerrit (that is, one change in review which is dependent on an earlier change which is simultaneously in review), and you need to make modifications to the earlier change, you effectively have to resubmit both changes (since the second change becomes dependent on a different "parent" commit)

That involves:

  • a third commit
  • a git rebase -i to reorder the commits
  • a git review again
Community
  • 1
  • 1
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250