5

I want to push a single commit to Gerrit without affecting other commits in the same topic branch. Unfortunately I don't have a test instance of Gerrit to experiment with.

Scenario: I have contributed a topic branch to the project, which is in review, and other developers have updated parts of it. Now I wish to make changes on top of their updates.

To do this I pull the changes by the other developer in the commit I wish to edit, do an interactive rebase locally to make my own changes, then push to Gerrit, making sure the Change-Id is still the same. This adds a new version of the file to the patchset for review.

Problem: When I tried to push a single commit to Gerrit, the other commits in the topic-branch were also pushed, overwriting changes by other developers.

Here is the syntax I used:

git push gerrit 3089c9f56542461dce738a9aa17bb743ed36e038:refs/publish/master/my-topic-branch

I presume that the other commits in the topic-branch were also pushed because of dependencies created by Gerrit.

Would this approach work instead, leaving out the topic branch title?:

git push gerrit 3089c9f56542461dce738a9aa17bb743ed36e038:refs/publish/master

I tried this approach successfully previously, pushing to the specific changeset:

git push gerrit a95cc0dcd7a8fd3e70b1243aa466a96de08ae731:refs/changes/12345

However, in trying this again I am now getting an unpack error:

error: unpack failed: error Missing tree 9172313b907b160d15e260d5f7d51689f467b858

Related question: When I pull the other developers' changes from Gerrit, how can I make sure that I have pulled all the files contributed in the topic-branch? If I select the topmost change in Gerrit in the topic-branch, and use the pull command stated in the web ui, it seems that some of the files in the topic-branch are updated locally, but not all. Do I need to go through every single commit in the topic-branch and issue the relevant pull command?

Lemmy
  • 397
  • 8
  • 18
  • Maybe I did not understand your question correctly. You said you "already pulled their changes(or commits) and rebased them interactively"...in the problem you mention "other commits in the topic branch were also pushed"...Since those changes are already present...why would you worry? or did you mean your other changes were pushed? – Vikram Jul 22 '13 at 15:37
  • The problem is that when I pull the changes from that particular commit, which is the only one I want to edit, not all of my local files, which are part of that topic-branch, are updated. See the 'Related question' section. So then when I push the changed commit, and the other commits in the topic-branch are also pushed, they are often older than the current ones on Gerrit, and overwrite changes made by other devs. – Lemmy Jul 22 '13 at 16:50
  • Regarding`Related Question` section: To make sure if you pulled all files contributed by topic branch,start at the very first `patchset 1` or a `patchset n` if you are sure that has all files you need. Do a `git pull --rebase refs/changes/#/#/patch#` starting from next patch until the most recent patchset. After you have rebased all patchsets.it is important to squash commits. strangely `git status` may or may not show any commits lying locally. – Vikram Jul 23 '13 at 14:51
  • however, on trying to push or you may get an error related to `squash commits` first.do `git rebase -i HEAD~x` where x is #patches applied, before you `push` to create new patchset. I am not 100% sure if I could answer you...I am also bit confused too about this scenario...I'll also wait and watch for a good answer – Vikram Jul 23 '13 at 14:53
  • @Vikram Thanks for your input - I'll try your suggested method for pulling down changes to the topic branch. – Lemmy Jul 23 '13 at 16:01

2 Answers2

1

I don't know the commands of hand but it would be something like this:

  1. Make new branch of the topic branch
  2. Merge the commit you want to add to the topic branch into this new branch
  3. Push the newly created merge to gerrit
0

you can do

git push origin <thelonghash>:master

but first you may need to do a rebase to take care of the related commits using

git rebase -i

For more information have a look here http://blog.dennisrobinson.name/push-only-one-commit-with-git/

Allen Luce
  • 7,859
  • 3
  • 40
  • 53
DrB
  • 264
  • 1
  • 3
  • 14