I want to change a pretty old commit message using:
git rebase -i sha1-of-commit^
That's nice, I do git commit --amend
and edit the message, but things get bad when I do:
git rebase --continue
I encounter multiple conflicts but don't understand why as the whole conflict resolution has obviously already been done in the past, and git should just move forward until all commits are rebased.
How can I finish the rebase quickly without having to handle these old conflicts? I just want to change a simple (and old) commit message after all...
If the commit only exists in your local repository and has not been pushed to GitHub.com, you can amend the commit message with the git commit --amend command. On the command line, navigate to the repository that contains the commit you want to amend. Type git commit --amend and press Enter.
The git commit --amend command is a convenient way to modify the most recent commit. It lets you combine staged changes with the previous commit instead of creating an entirely new commit. It can also be used to simply edit the previous commit message without changing its snapshot.
Make a small script in your /bin
directory (or any directory in your path) named git-reword-commit
. (You can name it whatever you want as long as the name starts with git-
. This will work regardless of whether there are merge commits or not.
#! /bin/bash
REV=$1
MESSAGE=$2
FILTER="test $(echo '$GIT_COMMIT') = $(git rev-parse $REV) && echo $MESSAGE || cat"
git filter-branch --msg-filter "$FILTER" -- --all
To use, execute
git reword-commit <commit> 'new message'
Warning: This will rewrite many commits, so the same issues that apply to rebase, apply here as well, i.e., you will need to force when you push, and other users will have to know about this.
Git puts your original refs (from before the filter-branch) in .git/refs/original
. You can use the following aliases to undo/confirm any filter-branch command.
git config alias.undo-filter-branch '! DIR=$(git rev-parse --git-dir); cp -r $DIR/refs/original/refs/ .git/; rm -r $DIR/refs/original/'
git config alias.confirm-filter-branch '! DIR=$(git rev-parse --git-dir); rm -r $DIR/refs/original/'
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With