如何从 .gitignore 中列出的存储库中删除文件而不更改空格 [英] How to remove files from repository listed in .gitignore without changing whitespace

查看:24
本文介绍了如何从 .gitignore 中列出的存储库中删除文件而不更改空格的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已阅读有关如何使用 git 命令从存储库中删除忽略文件中的文件的信息:将目录添加到 .gitignore 后从远程存储库中删除目录.

I have read about how to remove files that are in the ignore file from a repository using git commands here: Remove directory from remote repository after adding them to .gitignore.

我将 Visual Studio 2019 与 Azure DevOps 中的存储库一起使用.我使用了以下步骤:

I am using Visual studio 2019 with a repository in Azure DevOps. I have used these steps:

  1. 从 Git 资源管理器菜单中,在命令提示符中打开"
  2. git rm -r --cached .这告诉 git 停止跟踪所有内容,现在我的所有文件都在分阶段更改"中显示为已删除.和显示为更改"中添加的较少数量的文件.这看起来不错.我假设被忽略的文件不会再次添加回来,所以当我提交这些添加时,所有原本应该被忽略的文件都将在服务器上被删除.
  3. 舞台.现在看起来有问题.添加的文件显示为已修改.
  4. 当我在浏览器中查看更改时,按下按钮以查看它们的外观:"仅显示前 999 个更改.单击此处加载更多".我能看到的每个文件都有一个警告:该文件仅在空白处有所不同"
  1. From the Git Explorer Menu, "Open in Command Prompt"
  2. git rm -r --cached . This tells git to stop tracking everything and now I have all my files showing as deleted in "Staged Changes" and a smaller number of files showing as added in "Changes". This looks good. I assume ignored files are not added back again, so when I commit those additions all the files that should have been ignored in the first place will be deleted on the server.
  3. Stage. Now it looks like there's a problem. The added files are showing as modified.
  4. Push to see what they look like when I view the changes in the browser: "Only showing the first 999 changes. Click here to load more". And every file I can see has a warning: "The file differs only in whitespace"

我猜这与行尾有关,但几乎不可能查看更改.有没有办法阻止我使用这个过程时发生的空白变化?或者扭转空白变化?或者告诉 git 只检查删除?

I'm guessing it's about line endings but it makes it nearly impossible to review the changes. Is there a way to stop the whitespace changes occurring when I use this process? Or to reverse the whitespace changes? Or tell git to only check in the deletes?

TLDR 答案(来自 VonC):

git rm -r --cached .
git config --global core.autocrlf false
git add --renormalize .
git add .
git commit

推荐答案

舞台.现在看起来有问题.添加的文件显示为已修改.

Stage. Now it looks like there's a problem. The added files are showing as modified.

重复相同的过程,但在第 3 步(暂存)之前,添加:

Repeat the same process, but before step 3 (staging), add:

git config --global core.autocrlf false

这将确保有自动 eol(行尾)转换.
查看是否有 git add .(或 git add --renormalize . 使用 Git2.16+) 后跟 git status 仍然显示所有内容已修改.

That will make sure there is automatic eol (end of line) transformation.
See if a git add . (or git add --renormalize . with Git 2.16+) followed by a git status still show everything as modified.

OP Colin评论 以下工作:

git config --global core.autocrlf false
git add --renormalize .
git add .

这篇关于如何从 .gitignore 中列出的存储库中删除文件而不更改空格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆