1

I uploaded a patch X on gerrit, but by mistake I included a file Y that I shouldn't have included in the patch. Now, I want to submit a new patchset for X, without the file Y. Is it possible to do that

Steps to remove Y from new Patchset for X
Manually removed all the changes I made in Y (Not the best way to do that, but it removed Y from new Patchset for X)
git add .
git commit -s --amned
repo upload .

ankur
  • 11
  • 1
  • 3

3 Answers3

3

The short answer:

$ git reset HEAD^ <file to remove from commit>
$ git commit --amend

this will leave the <file> locally modified still, so assuming you didn't want the modification at all anymore, you can now revert that modification:

$ git checkout <file>

That is the quickest way to do it. Another option:

$ git log -n1 --oneline | cat
$ git reset --soft HEAD^
$ git reset <file to be unstaged>
$ git commit -C <sha1 commit hash from "git log" above>
Joe
  • 42,036
  • 13
  • 45
  • 61
0

is your change already reviewed ? If they are still waiting for review, you can just mark it as abandoned and get rid of them. Afterward you can commit the right code again.

if your changes reviewed and patch already merged into the git repository, the solution should not be different undoing a git push which is explained in the thread; Undoing a 'git push'

Community
  • 1
  • 1
clockworks
  • 3,755
  • 5
  • 37
  • 46
0

I haven't used Gerrit much, but you can amend the commit I believe.

Amending a commit

When amending a commit with git commit --amend, leave the Change-Id line unmodified in the commit message. This will allow Gerrit to automatically update the change with the amended commit.

http://gerrit.googlecode.com/svn/documentation/2.0/user-changeid.html#amend

After comment:

Are you ensuring that the Change-Id line is present and is the last line of your commit message? If Change-Id lines are not present in the commit messages, copy the line from the change's page on the web and put it in your commit message.

manojlds
  • 290,304
  • 63
  • 469
  • 417
  • Well, I just reverted the file to the state before it was committed and when I amended the commit, the file was not included. – ankur Apr 24 '11 at 09:40
  • @ankur - can you update your question with the steps you tried? – manojlds Apr 24 '11 at 16:44