Edit old commit message

Filter Branch Command Line Method

Add this piece of code to Git Bash for project but update the commit ID and the commit message:

git filter-branch --msg-filter "test $(echo '$GIT_COMMIT') = $(git rev-parse 05163c9b8ba425369c9b1619d43ed17b16604ec3) && echo 'Adding theme files' || cat" -- --all

Force push the commit to Github.com with this:

git push origin master --force

Filter Branch Bash Method

Issue: Can’t read PATH

Add this to file named git-reword-commit inside C:\bin

#! /bin/bash
path_to_git='/c/Program Files/Git/mingw64/bin/'
PATH=$PATH:$path_to_git
echo $PATH
export PATH
REV=$1
MESSAGE=$2
FILTER="test $(echo '$GIT_COMMIT') = $(git rev-parse $REV) && echo $MESSAGE || cat"
git filter-branch --msg-filter "$FILTER" -- --all

Open cmd and go to directory C:\bin then type

bash git-reword-commit

PATH is supposed to make the git command work but get these errors:

': not a valid identifier: export: `PATH
git-reword-commit: line 7: git: command not found
git-reword-commit: line 8: git: command not found

Rebase Method

Issue: Only changes on one branch… if the change happened on Master you’ll only see on Master and not Develop. It also separates the two branches and they no longer intertwine.

Figure out how many commits to go back. If you get an error message you went back too far:

git rebase -i HEAD~133

If you didn’t go far back enough then undo it

git rebase --abort

When you see your commit, use the up and down keys to get to the line. Press “i” to enable editing of text. Change “pick” to “reword” and press “Esc” then type “:wq” which will save the file.

pick e499d89 Corrected syntax error 
pick 0c39034 Adding code prism.js
pick f7fde4a More css updates

# Rebase 9fdb3bd..f7fde4a onto 9fdb3bd
#
# Commands:
# p, pick = use commit
# r, reword = use commit, but edit the commit message
# e, edit = use commit, but stop for amending
# s, squash = use commit, but meld into previous commit
# f, fixup = like "squash", but discard this commit's log message
# x, exec = run command (the rest of the line) using shell
#
# These lines can be re-ordered; they are executed from top to bottom.
#
# If you remove a line here THAT COMMIT WILL BE LOST.
#
# However, if you remove everything, the rebase will be aborted.
#
# Note that empty commits are commented out

After I saved and closed, it then opened up the commit I renamed and I saved that with “:wq” as well.

Finish the rebase with:

git rebase --continue

Force push the commit to Github.com with this:

git push origin master --force

Leave a Reply

Your email address will not be published. Required fields are marked *