有没有一种简单的方法可以自动对任何只有空格更改的文件进行git checkout?我正在处理从Eclipse运行的Windows和一些代码生成,所以我得到了新行更改和空白更改,这些更改阻碍了我的工作流程中的噪音,并且难以跟踪实际更改.
即使只是一种很好的方式来报告哪些文件有真正的变化而哪些不是一个开始,而不是必须为每个文件做一个diff -w
Ken*_*sen 37
要暂存不仅仅是空白更改的更改,您可以执行以下操作:
git diff -U0 -w --no-color | git apply --cached --ignore-whitespace --unidiff-zero -
之后,要删除所有未分级的更改(仅在空格中有所不同的更改),您可以执行以下操作:
git checkout .
通过执行a git reset --mixed
并从此答案的顶部继续来取消您的更改.请注意,这mixed
是默认模式,可以省略.
(there\xe2\x80\x99s可能是一种更聪明的方法,但这对我有用)
\n\nmybranch=master\ngit checkout -b tmp origin/master\n\n# compute the non-ws diff to mybranch and apply it\ngit diff -U0 -w --no-color $mybranch | git apply -R --cached --ignore-whitespace --unidiff-zero -\n\ngit commit -m "non ws changes"\ngit reset --hard # discard all non-staged data\n
Run Code Online (Sandbox Code Playgroud)\n\n您现在位于新的“tmp”分支上。您可能想要清理(注意:这会丢失历史记录$mybranch
)
git checkout $mybranch\ngit reset --hard tmp\ngit branch -D tmp\n
Run Code Online (Sandbox Code Playgroud)\n
这很可能是行尾问题;Windows 使用 CRLF(回车 + 换行,或\r\n
)换行符,而大多数其他系统使用 LF(换行,或\n
)。幸运的是,Git 可以规范化文件,以便它们在 repo中始终存储为 LF,但在 Windows 上将作为 CRLF 检出。您可以通过在 Windows 上设置core.autocrlf
为来执行此操作true
:
$ git config --global core.autocrlf true
Run Code Online (Sandbox Code Playgroud)
并在 Mac 和 Linux 上设置core.autocrlf
为input
:
$ git config --global core.autocrlf input
Run Code Online (Sandbox Code Playgroud)
此处提供了更多信息(向下滚动到标题为core.autocrlf的部分)。
归档时间: |
|
查看次数: |
8336 次 |
最近记录: |