Reputation: 3071
I have uploaded a gerrit and now I want to delete some files from my commit, how can I do that?
Upvotes: 2
Views: 21013
Reputation: 856
Say you have commited three files a.java, b.java, c.java to gerrit and you want to remove b.java from the commit. Follow the below steps.
Use the below command to remove the file from the commit. (Do this for as many files you want to remove.)
git reset HEAD^ path/to/file/b.java
Amend the commit with the below command.
git commit --amend
Upvotes: 10
Reputation: 5059
So you need to generate a new patch set that will replace the old one. Assuming you haven't commited anything else since the commit you are trying to edit, do
git rm <files>
git commit --amend
You have installed the gerrit commit hook, haven't you? If you have, you are good to go and are ready to push. You you don't have it, you need to copy the Change-id line from the gerrit web interface to the end of your commit message, or gerrit won't be able to replace the previous patch set with the new one.
When you committed the file (and you have the same Change-id line there as you had in patch set 1), push the fix to gerrit
git push origin HEAD:refs/for/master
or whatever repository and branch you are pushing to.
In the future, you should install the commit hook as soon as you clone the repository from gerrit. If you clone with e.g.
git clone ssh://firstname.lastname@gerrit/project
you can get the commit hook with
cd project
scp firstname.lastname@gerrit:hooks/commit-msg .git/hooks
Substitute paths and machine names that apply to your case.
Upvotes: 5