Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
How to edit a commit with interactive rebase

While on a branch with a couple of commits, you can edit a commit with interactive rebase. This should be used sparingly and only on branches and never on master.

  1. Checkout the branch

$ git checkout my-branch

  1. Get the ref of the commit that you want to edit from the commit log. (e.g. 67b191fc62eda52b5b208cc4de50df7144a03171)

$ git log

  1. Begin rebasing. (Note: The carot at the end of your commit ref is important to start from the commit before your commit.)

$ git rebase --interactive 67b191fc62eda52b5b208cc4de50df7144a03171^

  1. Change "pick" to "edit" for your commit and save.

  2. Do not be alarmed. Your commit will be applied first and then the command will pause to allow you to make amendments. Make your changes then commit them.

$ git commit --all --amend

  1. The command will remain paused for additional amendments. When all is good, continue to reaplly the rest of your commits.

$ git rebase --continue

  1. Not that your branch is in a good state. Push to origin.

$ git push --force

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.