Skip to end of metadata
Go to start of metadata

Situation: I'm working on a feature branch with multiple commits that are all part of a single pull request.  I noticed that the 3rd last commit (i.e. HEAD~3) isn't correct and needs to be updated.  In this specific situation I missed the removal of two binary files.  The patch that I applied didn't remove them.  No sweat, we still can fix this without having to mess with the latest two commits.

Step-by-step guide

  1. Start the interactive rebase via the git rebase -i HEAD~3 command.  HEAD~3 allows us to work with the three most recent commits.
  2. In the interactive editor we replace the pick of the commit we want to edit with the edit command to amend to this commit.

  3. After saving and closing the editor git will rebase and prompt us to do our amendments.

  4. Now we can do the needed modifications to this specific commit.  In my case it's the removal of the two binary files.  Removal of files need an additional flag when performing the git add commend.  --all in this case works well.

  5. Use git commit --amend to commit your amended commit.  You now get the opportunity to update the original commit message.  As usual do a save and close to continue.
  6. Now use git rebase --continue to finish up the rebasing.
  7. Push the changes to the GitHub repository via git push --force origin <branch>