git rebase to remove a commit

Viewed 6405

I have the following change history in my git repository:

---X---Y---Z---A---B---C

I began working from a base of code Z and made three changes A, B and C. Each of these changes has been uploaded as separate reviews on Gerrit and each depends on the change before it.

Following a review I want to remove change A, so that my change history is:

---X---Y---Z---B---C

What is the correct flow of git rebase -i and git commit to get this to work?

I assumed the following:

  1. Use git rebase -i HEAD~3 to show the last three commits. This shows the file contents:

    pick 1234567 Commit A message
    pick 1a2b3c4 Commit B message
    pick abcdefg Commit C message

  2. I can then delete the first line and save the file to remove the first commit.

  3. This is where I get stuck... If I try to git commit --amend I can only amend the commit of C. I thus don't know how to push my rebase change to Gerrit for review using repo upload . or git push

I am using Gerrit 2.2 so there is no rebase button on the review page.

2 Answers
Related