use*_*529 5 git whitespace ignore gitignore removing-whitespace
我们可以使用一些忽略空格的方法来做比较:
1)git diff --ignore-space-at-eol#忽略EOL处空格的更改。
2)git diff --ignore-space-change/ git diff -b#忽略空白量的变化。
3)git diff --ignore-all-space/ git diff -w#全空格忽略
我们能做的
git apply --ignore-whitespace\ git apply --ignore-space-change#应用补丁时忽略白蜡
但是,如何排除具有空格变化的文件git add *呢?
这些解决方案不适用于我:
1)
git diff -w --no-color | git apply --cached --ignore-whitespace
Run Code Online (Sandbox Code Playgroud)
-有时会写入错误,并且不会添加新文件进行跟踪。
2)
git add `git diff -w --ignore-submodules |grep "^[+][+][+]" |cut -c7-`
Run Code Online (Sandbox Code Playgroud)
-它会写错误并且什么也不做(可能是因为我有二进制文件,而不仅仅是文本文件)
PS:也许有办法用最后一次提交的文件替换文件(文件末尾有行空格,EOF之前有空格)。
这个问题的唯一真正的解决方案是。
解决方案是使用特殊设置重新创建 git 存储库,然后将原始提交从一种签出状态复制到此存储库。
源不良存储库:
/home/用户/truepower
新的好存储库:
/home/用户/onepower
cd /home/user
rm -rf ./onepower
mkdir ./onepower
cd ./onepower
git init
# set style of lineendings to be autoconverted to Linux/Unix LF
#git config core.autocrlf true # uncomment this if you prefer Windows CRLF style
git config core.autocrlf input # comment this if you prefer Windows CRLF style
# set trailing whitespace (and other similar) to ignore
git config core.whitespace \
trailing-space,space-before-tab,indent-with-non-tab
# you can use git config --global ... if you want global settings changing.
cd ../truepower
git log
Run Code Online (Sandbox Code Playgroud)
提交cccc
提交 bbbb
提交aaaa
cd ../truepower
git checkout aaaa
cd ../onepower
rm -rf ./*
cp -a ../truepower/* ./
git add -A
git commit -m "fixed aaaa"
cd ../truepower
git checkout bbbb
cd ../onepower
rm -rf ./*
cp -a ../truepower/* ./
git add -A
git commit -m "fixed bbbb"
cd ../truepower
git checkout cccc
cd ../onepower
rm -rf ./*
cp -a ../truepower/* ./
git add -A
git commit -m "fixed cccc"
Run Code Online (Sandbox Code Playgroud)
现在您可以删除旧的坏 ../truepower 并使用新的 ../onepower git 存储库。
顺便说一句,在此之后,您将不会遇到此存储库的问题,即文件末尾、字符串末尾以及字符串开头的部分空格更改。但当然,字符串中间的空格变化将被解释为变化。
在以下帮助下找到解决方案:http://git-scm.com/book/en/Customizing-Git-Git-Configuration#Formatting-and-Whitespace
| 归档时间: |
|
| 查看次数: |
4758 次 |
| 最近记录: |