0

I have a repo with master branch. I have patch-sets 1 to 10 amended in a single commit. Now I have amended the 11th patch-set in that commit and pushed the code in gerrit. I want to revert the commit back to 10th commit and push. How do I revert, as if I see git log, it does not list the commits in that patch-set. But it rather takes it as a single commit.

I have explained the sequence of actions done below.

Sequence of actions
1. Initially for patch-set #1 
git clone repo
made changes to code 
git commit 
git push HEAD:refs/for/master => pushes to gerrit
Let us assume gerrit patch# generated is 12345

2. mkdir new_dir
git clone repo
git checkout ssh:user@gerrit1.xxx.com/development refs/changes/1/12345/1 && git checkout FETCH_HEAD
made modifications for patch-set 2 on patch-set 1
git commit --amend
git push HEAD:refs/for/master => pushes to gerrit 

Now gerrit patch#12345 has following commits/patch-sets
1, 2

3. Repeated step 2 for patch-sets 3 to 11
Now gerrit patch#12345 has following commits/patch-sets
1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11

4. Got to know path-set 11 is redundant, has to be reverted, so that patch-set#10 is the latest and 11 should be discarded, so that gerrit patch#12345 has commits/patch-sets 1, 2, 3, 4, 5, 6, 7, 8, 9, and 10 only (not 11).


How do I achieve step 4?

When I tried git rebase -i with the commit-id it says fatal bad object.

Please let me know how to resolve this using git commands, or should I do it manually.

Thanks.

TechTotie
  • 127
  • 1
  • 15
  • I'm not sure how your situation looks like but when you amended this commits you "don't see" them now. How about to back your history with reflog? – dunajski Jan 13 '20 at 09:11
  • "I have patch-sets 1 to 10 amended in a single commit." Do you mean you squashed them in one commit? Do you want to revert that commit? – dunajski Jan 13 '20 at 09:13
  • @dunajski I will explain the situation here. I have clean repo with master branch. I made changes and did a commit #1 and pushed it into a separate patch-set in gerrit. Later I made some more additions and then did an amend to the previous commit#1, this will be commit#2 and this went on for months. Now I have 10 patch-sets in a single commit commit#10 visible in git log. But in gerrit I have separate 10 patch-sets. I have made the 11th commit and pushed in gerrit, but want to revert it back to commit#10. I am using gerrit. Is it possible. (Question edited as using gerrit) – TechTotie Jan 13 '20 at 09:16
  • can you please try with ----> git reset --soft HEAD~1 – Muzzamil Jan 13 '20 at 10:40
  • @Muzzamil No it won't help as git sees the entire gerrit patch as a single commit. @ Muzzamil and @ dunajski I have modified the question to make it more clear. Please let me know, if any more details are required for understanding. – TechTotie Jan 13 '20 at 12:07

1 Answers1

1

The answer is in your question. Instead of checking out patchset 1 you just need to fetch back patchset 10.

git checkout ssh:user@gerrit1.xxx.com/development refs/changes/1/12345/10 && git checkout FETCH_HEAD
git commit --amend
git push HEAD:refs/for/master

You will need to amend your patchset 10 for you to be able to push it again as Gerrit will not allow you to re-push the same patchset, after this you can submit patchset 11.

Alternatively you could inspect your reflog and find patchset 11 in there. But the easiest way is to get the command from the Gerrit Download Commands

uncletall
  • 6,609
  • 1
  • 27
  • 52