Note: similar question as this one, but with some important changes.
I have the following function to rewrite the date of a commit, given the commit id:
rewrite-commit-date () {
local commit="$1"
local newdate="$2"
newdate="$(date -R --date "$newdate")"
echo ">>>> Rewriting commit $commit date: $newdate"
git filter-branch --env-filter \
"if test \$GIT_COMMIT = '$commit'
then
export GIT_AUTHOR_DATE
export GIT_COMMITTER_DATE
GIT_AUTHOR_DATE='$newdate'
GIT_COMMITTER_DATE='$newdate'
fi" &&
rm -fr "$(git rev-parse --git-dir)/refs/original/"
}
I am trying to implement a similar function rewrite-commit-message to change the commit message. What I want is:
- The function
rewrite-commit-messageaccepts two parameters: thecommit_id, and thenew_commit_message - There is no need to know the old commit message: having the
commit_idis enough to know which commit to change - No
git commit --amend, since this is related to old commits (not necessarily to the most recent commit) - No worries about rewriting history and the master repo: I am working in a feature branch, and I am allowed to do
git push -f - I would like to use
filter-branchfor this, but I am not sure how to:- apply the change to a specific commit: the
testused in therewrite-commit-datefunction is used inenv-filter, but I am not going to doenv-filterhere, since I do not want to change anything related to the commit environment, but the commit message. - how to force a commit message? The
--msg-filterneeds the original commit message. I do not care about the original commit message. Is there a--force-msg-filteror similar?
- apply the change to a specific commit: the
What I am looking for is similar to this, but with some caveats:
- Do not apply the change to a range of commits, but to a specific commit
- I do not care about the original commit message, since I want to completely overwrite it