Skip to content

Instantly share code, notes, and snippets.

Embed
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

@droopycom

This comment has been minimized.

Copy link

@droopycom droopycom commented May 3, 2018

What exactly happen when you say: "Your commit will be applied first". Is a new commit created ? Or are the changes applied to the working tree only? Or to the index?

@bryanbraun

This comment has been minimized.

Copy link

@bryanbraun bryanbraun commented Mar 13, 2019

@droopycom, I had the same question so I dug into it and wrote up some more details about the process here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment