我正在與團隊一起使用git,并希望從diff,日志,合并等中刪除空格更改。我假設最簡單的方法是讓git自動刪除結尾的空格(以及其他空格錯誤) )中的所有提交。我試圖將以下內容添加到~/.gitconfig文件中,但是在提交時它什么也沒做。也許它是為不同的東西而設計的。有什么解決辦法?[core] whitespace = trailing-space,space-before-tab[apply] whitespace = fix如果有人對紅寶石有任何特定想法,我會使用紅寶石。下一步是提交之前自動進行代碼格式化,但這是一個難題,并且不會真正引起大問題。
3 回答

BIG陽
TA貢獻1859條經驗 獲得超6個贊
我發現了一個git pre-commit鉤子,該鉤子刪除了結尾的空格。
#!/bin/sh
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"
git add "$FILE"
done
exit
- 3 回答
- 0 關注
- 950 瀏覽
添加回答
舉報
0/150
提交
取消