I have uploaded a gerrit and now I want to delete some files from my commit, how can I do that?
-
Do you mean you have uploaded a patch set to gerrit for review and want to edit the patch set before it's merged? – Kalle Pokki Jan 17 '13 at 20:19
2 Answers
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.
- If you are in a different branch, cherry-pick the particular commit.
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

- 826
- 10
- 13
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.

- 4,939
- 2
- 17
- 18
-
i dont have gerrit commit hook..how can i install it?what is the use of it? – user1934146 Jan 18 '13 at 15:54
-
If you use gerrit effectively, i.e. want to fix the commits according to review comments, you need the hook so that gerrit can associate the following patch sets to the same intended change and replace the previous patch sets. I'll update the answer to include how to get the commit hook. – Kalle Pokki Jan 18 '13 at 16:34