For example, if you want to modify three previous commit messages,
It is stated thatIs there any easier way to do it?
git
Git rebase-i<commit-id>
and save effort.
The following assumptions assume that bash
is running.
git log --pretty=oneline | cat -- number-nonblank; select id in$( git log --pretty=oneline | cut --delimiter='--fields=1); do gate rebase-i "$id"; break; done
Unfortunately, I couldn't find a way to make it a git alias, but I was able to write it down in bashrc as a function.
selrb(){
git log --pretty=oneline | cat -- number-nonblank & & select id in$ (git log --pretty=oneline | cut --delimiter='--fields=1);
do
git rebase-i "$id";
break;
done
}
You can edit commit messages directly with git commit --amend
, but I think the only way to rewrite two or more previous commit messages is by rebase
.
#!/bin/bash
refspec = "$1"
export MSG = "$2"
export REWRITE_REF=$(git log-n1 --format=%H"$refspec")
git filter-branch --msg-filter'
if [$GIT_COMMIT=$REWRITE_REF]
then
printf "%s\n" "$MSG"
else
cat
fi
' "$refspec"^..HEAD
path/to/rewrite-history.sh master^3 "commit message"
© 2024 OneMinuteCode. All rights reserved.