@vbabka I wouldn't expect git to be able to deny you your wish to amend (although there are a lot of config options).
And while you probably could hack some files in .git
, take refs from reflog, set some tags and thus restore the pre-amend state manually, in many cases it is probably still harder than doing the whole rebase againโฆ
git rerere
could be useful, but I have exactly zero experience with that yet.
Reading this toot is like feeling old paper cuts re-opening
Git reflog covers multitude of sins?
@vbabka I believe you can still get the old commit OID before the amend. From that, recover the non-squashed old commit, then restore the working tree from the amended tree OID and commit it as a merge commit ("git rebase --continue"). I haven't checked this idea, but it should work.
@vbabka How did you even arrive there? I have tried to verify my idea and I'm running into this:
petr@mordecai:~/research/botch-up-merge> git commit --amend
fatal: You are in the middle of a merge -- cannot amend.
git version 2.45.2
@vbabka put this in your .bashrc or something?
git() {
if [ -e "$(command git rev-parse --git-dir)/rebase-merge" ] && (echo "$@" | grep -q "\--amend")
then
echo "error: you tried to do git commit --amend during a conflict resolution, didn't you?"
return 1
fi
command git "$@"
}
@vbabka How about this?
git() {
git_dir="$(command git rev-parse --git-dir)"
if [ -e "$git_dir/rebase-merge" ] && [ -e "$git_dir/MERGE_MSG" ] && (echo "$@" | grep -q "\--amend")
then
echo "error: you tried to do git commit --amend during a conflict resolution, didn't you?"
return 1
fi
command git "$@"
}