Skip to content

Instantly share code, notes, and snippets.

@mdb
Last active October 25, 2022 12:17
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save mdb/4288296 to your computer and use it in GitHub Desktop.
Save mdb/4288296 to your computer and use it in GitHub Desktop.
How to Amend a Commit
# View the log to find the commit you want to edit:
git log
# Quit out of the log
q
# Rebase from the commit you want to edit, in interactive mode:
git rebase SOME_COMMIT_ID^ --interactive
# This will open an interactive menu in Vi
# Change 'pick' to 'edit' to the left of the commit you want to amend
# :wq to save and quit
# Make some changes to some_file
# Add some_file to staging area when you're ready to commit:
git add some_file
# Commit some_file with the --amend flag:
git commit some_file --amend
# This will open your original commit message in Vi
# You can edit it or leave it as is
# :wq to save and quit
# Continue your rebase
git rebase --continue
# Push your changes like normal
git push
# or, in Gerrit world:
git push origin HEAD:refs/for/whatever_branch
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment