"un-committing" a file from a pushed changeset in gerrit


I have a commit with two files changed (file a and b), I pushed it to gerrit repo (but not yet merged). Now I realize I dont need to update b. How do I push a new changeset that removes/un-commits b and only includes file a?


In your your local repository do the following:

  1. Remove file-b from the commit

    git reset HEAD^ -- file-b
  2. Amend the commit without the file-b

    git commit --amend
  3. Discard file-b changes

    git checkout -- file-b
  4. Confirm that everything is OK

    git status
    git log
    git diff HEAD^ HEAD
  5. Push the new commit to Gerrit (new patchset)

    git push origin HEAD:refs/for/master

Answered By – Marcelo Ávila de Oliveira

This Answer collected from stackoverflow, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0

Leave a Reply

(*) Required, Your email will not be published