Git 只添加非空格更改

4

我试图仅提交相关更改,并保留格式。

在我的 .gitconfig 文件中,我删除了 core.autocrlf = input 行以跳过行结束转换。

但现在我不知道为什么我的行结束符仍然被转换。

已经检查了类似的解决方案,但没有效果。 我只想提交非空格的更改。

我尝试了:

git add myfile

git diff HEAD
--- /dev/null
+++ b/profiles/minimal/minimal.info
@@ -0,0 +1,6 @@
...content of file here (practically all is changed)

现在需要去除空格。
git diff HEAD -w | git apply --cached --ignore-whitespace

我收到一个错误提示

error: myfile: already exists in index
1个回答

2
您只是想添加已经被添加到索引中的文件。您不能再次添加它。看起来您已经执行了此命令或使用git add手动添加了该文件。
该命令的作用是什么(以便其他人可以学习):
git diff HEAD -w | git apply --cached --ignore-whitespace

以下是它所做的事情:

# Generate the diff between HEAD to index
git diff HEAD -w

# apply the patch to the index

git-apply

将补丁应用到文件和/或索引中


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接