Reputation: 31248
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?
Upvotes: 1
Views: 350
Reputation: 6842
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
Upvotes: 2
Reputation: 1324937
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:
git review
againUpvotes: 1