-
-
Save lolindrath/4454638 to your computer and use it in GitHub Desktop.
How to Amend a Git Commit
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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