我已经对 git repo 进行了相当大的提交(更改了 60 个文件,插入了 1635 个(+),删除了 3 个(-)),现在我意识到我使用了空格进行缩进,而其余代码则使用了制表符。
因此,我想替换制表符的空格,但仅限于该提交更改的行,因为我不想修改可能使用空格的其他代码。
我怎样才能做到这一点?我不在乎它是否会修改工作目录或原始提交,两者都可以。
你可以尝试我写的一个小脚本(washamend)。首先提交,然后运行此脚本进行清理。它使用修改
要做到这一点。
#!/bin/bash -e
#
# Rewrite the last commit to remove any trailing whitespace
# in the new version of changed lines.
# Then replace space-based indentation with TAB based indentation
# based on TABS at every eight position
#
[[ -z $TRACE ]] || set -x
trap "rm -f $tmpf" 0
tmpf1=$TMP/$$.1.diff
tmpf2=$TMP/$$.2.diff
git show --binary >$tmpf1
perl -p -e 's/^(\+.*?)[ \t]+$/$1/; while(m/^(\+\t*)( {1,7}\t| {8})(.*)/) { $_=$1."\t".$3."\n"; }' <$tmpf1 >$tmpf2
if ! cmp -s $tmpf1 $tmpf2
then
git apply --binary --index -R --whitespace=nowarn $tmpf1
git apply --binary --index $tmpf2
GIT_EDITOR=true git commit --amend
else
echo "No changes"
fi
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)