Skip to content

Instantly share code, notes, and snippets.

@undrafted
Created April 17, 2020 10:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save undrafted/d082d3e5fc0fdfbf871722fb4bc25a04 to your computer and use it in GitHub Desktop.
Save undrafted/d082d3e5fc0fdfbf871722fb4bc25a04 to your computer and use it in GitHub Desktop.
https://stackoverflow.com/questions/1186535/how-to-modify-a-specified-commit
You can use git rebase. For example, if you want to modify commit bbc643cd, run
$ git rebase --interactive 'bbc643cd^'
Please note the caret ^ at the end of the command, because you need actually to rebase back to the commit before the one you wish to modify.
In the default editor, modify pick to edit in the line mentioning 'bbc643cd'.
Save the file and exit: git will interpret and automatically execute the commands in the file. You will find yourself in the previous situation in which you just had created commit bbc643cd.
At this point, bbc643cd is your last commit and you can easily amend it: make your changes and then commit them with the command:
$ git commit --all --amend --no-edit
After that, type:
$ 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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment