GIT: updating a commit, after a reject on review
This information is for Scilab developers and code contributors. See GIT for a table of content. If you are a user of Scilab, you probably don't need to look at this.
As we use Gerrit to review our commits, it often happens that we have to update a commit several times before the commit gets accepted. This page details a process to get the commit updated after manual changes.
Contents
Summary of the process
Here is a summary.
1. Getting the commit to be updated
git fetch ssh://firstname.lastname@git.scilab.org:29418/scilab refs/changes/... && git cherry-pick FETCH_HEAD
2. Make manual changes to the files
3. Update the commit into Gerrit
git add foo.txt git commit --amend git push
4. Getting clean back again
git fetch git reset --hard remotes/origin/master
Here is the detailed log.
Getting the commit to be updated
user@MYMACHINE /c/mygitrepository/scilab/scilab/scilab (master) $ git fetch ssh://firstname.lastname@git.scilab.org:29418/scilab refs/changes/83/1883/2 && git cherry-pick FETCH_HEAD Enter passphrase for key '/c/Users/user/.ssh/id_rsa': From ssh://git.scilab.org:29418/scilab * branch refs/changes/83/1883/2 -> FETCH_HEAD Finished one cherry-pick. [master e6aeb03] statistics: Fixed bug #7768: for cdfgam, the Scale parameter was, in fact, the Rate 5 files changed, 324 insertions(+), 102 deletions(-) rewrite scilab/modules/statistics/tests/unit_tests/cdfgam.dia.ref (80%) rewrite scilab/modules/statistics/tests/unit_tests/cdfgam.tst (70%) user@MYMACHINE /c/mygitrepository/scilab/scilab/scilab (master) $ git status # On branch master # Your branch is ahead of 'origin/master' by 1 commit. # # Changed but not updated: # (use "git add <file>..." to update what will be committed) # (use "git checkout -- <file>..." to discard changes in working directory) # # modified: modules/statistics/help/en_US/cdfgam.xml # modified: modules/statistics/tests/unit_tests/cdfgam.dia.ref # modified: modules/statistics/tests/unit_tests/cdfgam.tst # no changes added to commit (use "git add" and/or "git commit -a")
Update the commit into Gerrit
user@MYMACHINE /c/mygitrepository/scilab/scilab/scilab (master) $ git add modules/statistics/help/en_US/cdfgam.xml modules/statistics/tests/unit_tests/cdfgam.dia.ref modules/statistics/tests/unit_tests/cdfgam.tst user@MYMACHINE /c/mygitrepository/scilab/scilab/scilab (master) $ git commit --amend [master fa3deed] statistics: Fixed bug #7768: for cdfgam, the Scale parameter was, in fact, the Rate 5 files changed, 334 insertions(+), 102 deletions(-) rewrite scilab/modules/statistics/tests/unit_tests/cdfgam.dia.ref (80%) rewrite scilab/modules/statistics/tests/unit_tests/cdfgam.tst (70%) user@MYMACHINE /c/mygitrepository/scilab/scilab/scilab (master) $ git push Enter passphrase for key '/c/Users/user/.ssh/id_rsa': Counting objects: 31, done. Delta compression using up to 4 threads. Compressing objects: 100% (16/16), done. Writing objects: 100% (16/16), 3.94 KiB, done. Total 16 (delta 12), reused 0 (delta 0) remote: (W) fa3dee: commit subject >65 characters; use shorter first paragraph remote: (W) fa3dee: commit message lines >70 characters; manually wrap lines To ssh://firstname.lastname@git.scilab.org:29418/scilab * [new branch] master -> refs/for/master
Getting clean back again
user@MYMACHINE /c/mygitrepository/scilab/scilab/scilab (master) $ git fetch Enter passphrase for key '/c/Users/user/.ssh/id_rsa': user@MYMACHINE /c/mygitrepository/scilab/scilab/scilab (master) $ git reset --hard remotes/origin/master HEAD is now at a1806f9 Bad merge in codereviewx 1808 user@MYMACHINE /c/mygitrepository/scilab/scilab/scilab (master) $ git status # On branch master nothing to commit (working directory clean)