Skip to content

Instantly share code, notes, and snippets.

@lolindrath
Forked from mdb/gist:4288296
Last active January 8, 2020 19:57
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save lolindrath/4454638 to your computer and use it in GitHub Desktop.
Save lolindrath/4454638 to your computer and use it in GitHub Desktop.
How to Amend a Git 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
# (Gerrit Specific) Ensure that the Change-Id is present in the
# commit message, otherwise copy it in on its own line from Gerrit
# 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/master
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment