這是怎麼回事在this pre-commit hook?我認爲更改文件會導致它們被重新整理。這個預提交鉤子如何修復尾隨空格?
#!/bin/sh
#
# A git hook script to find and fix trailing whitespace
# in your commits. Bypass it with the --no-verify option
# to git-commit
#
if git-rev-parse --verify HEAD >/dev/null 2>&1 ; then
against=HEAD
else
# Initial commit: diff against an empty tree object
against=4b825dc642cb6eb9a060e54bf8d69288fbee4904
fi
# Find files with trailing whitespace
for FILE in `exec git diff-index --check --cached $against -- | sed '/^[+-]/d' | sed -r 's/:[0-9]+:.*//' | uniq` ; do
# Fix them!
sed -i 's/[[:space:]]*$//' "$FILE"
done
# Now we can commit
exit
我認爲這個想法是去掉結尾的空白在這次提交觸及的所有文件。
對索引*進行的任何修改都會被考慮到,是的。儘管如此,您仍然需要在'pre-commit'鉤子中'git add'修改任何文件。 – sschuberth 2014-08-27 21:55:15