gpt4 book ai didi

git - 如何使用 git stash 忽略尾随空格错误

转载 作者:行者123 更新时间:2023-12-04 13:39:36 24 4
gpt4 key购买 nike

我有一个不寻常的 git 问题。我从一个我有一段时间没有使用过的仓库中提取出来,为了简单起见,假设我有两个分支,develop 和 master。我已经在开发中,并检查了主人。我没有做任何更改,我只是在查看文件。当我去 checkout develop 时,我不能因为 README.md 被修改了。 Git diff 显示整个文件已更改,内容相同,所以我认为这是某种空白错误。

我做了 git checkout -- README.md,它仍然出现修改。然后我尝试了 git stash -p (这样我就可以存储该文件)。这给了我:

warning: 3 lines add whitespace errors.

它接着说:
warning: squelched 55 whitespace errors
warning: 60 lines add whitespace errors.

而且文件还在修改中。

有什么办法可以解决这些错误吗?是什么原因造成的?

最佳答案

正如你上面提到的,问题被命名为 尾随空格 .
Git 有几种处理空格的方法。你可以在这里读到它:
https://git-scm.com/book/en/v2/Customizing-Git-Git-Configuration#_formatting_and_whitespace
您可以尝试设置配置值:

$ git config --global core.whitespace \
trailing-space, \
-space-before-tab, \
indent-with-non-tab, \
tab-in-indent, \
cr-at-eol
当 git 从存储中 pop 内容时,它会使用 apply 将其添加回工作目录。命令,因此您可以禁用 apply使用此配置发出警告
git config --global apply.whitespace nowarn
or
git config --global core.whitespace fix

#core.whitespaceA comma separated list of common whitespace problems to notice.
git diff will use color.diff.whitespace to highlight them,
and git apply --whitespace=error will consider them as errors.


You can prefix - to disable any of them (e.g. -trailing-space):


###blank-at-eoltreats trailing whitespaces at the end of the line as an error (enabled by default).


###space-before-tabtreats a space character that appears immediately before a tab character in the initial indent part of the line as an error (enabled by default).


###indent-with-non-tabtreats a line that is indented with space characters instead of the equivalent tabs as an error (not enabled by default).


###tab-in-indenttreats a tab character in the initial indent part of the line as an error (not enabled by default).


###blank-at-eoftreats blank lines added at the end of file as an error (enabled by default).


###trailing-spaceis a short-hand to cover both blank-at-eol and blank-at-eof.


###cr-at-eoltreats a carriage-return at the end of line as part of the line terminator, i.e. with it, trailing-space does not trigger if the character before such a carriage-return is not a whitespace (not enabled by default).


###tabwidth=<n>tells how many character positions a tab occupies; this is relevant for indent-with-non-tab and when Git fixes tab-in-indent errors. The default tab width is 8. Allowed values are 1 to 63.

关于git - 如何使用 git stash 忽略尾随空格错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41879816/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com