Sam Liao Sam Liao - 28 days ago 6x
Git Question

How to modify a specified commit in git?

I usually submit a list of commits for review. If I have:

  • HEAD

  • Commit3

  • Commit2

  • Commit1

I know that I can modify head commit with
git commit --amend
, but how can I modify
, given that it is not the


You can use git rebase, for example, if you want to modify back to commit bbc643cd, run

$ git rebase --interactive 'bbc643cd^'

In the default editor, modify pick to edit in the line whose commit you want to modify. Make your changes and then commit them with the same message you had before:

$ git commit --all --amend --no-edit

to modify the commit, and after that

$ git rebase --continue

to return back to the previous head commit.

WARNING: Note that this will change the SHA-1 of that commit as well as all children -- in other words, this rewrites the history from that point forward. You can break repos doing this if you push using the command git push --force