如何停止跟踪并忽略Git中文件的更改? [英] How to stop tracking and ignore changes to a file in Git?

查看:111
本文介绍了如何停止跟踪并忽略Git中文件的更改?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我克隆了一个包含 .csproj 文件的项目。我不需要像/我的本地 csproj 文件被Git跟踪(或者在创建补丁时被调出),但显然它们在项目中是必需的。 p>

我已将 *。csproj 添加到我的本地 .gitignore ,但这些文件已经存在于回购站中。



当我输入git status时,它显示我对 csproj 我不感兴趣跟踪或提交补丁。



如何从我的个人回购中删除这些文件的跟踪(但将它们保留在所以我可以使用它们),以便在执行状态(或创建修补程序)时看不到更改?

是否存在正确/规范的方法处理这种情况?

解决方案

只要调用 git rm --cached 在你想从版本控制中删除的每个文件都应该没问题。只要你的本地忽略模式是正确的,你将不会看到这些文件包含在输出的git状态。



请注意,此解决方案从存储库中删除文件,因此所有开发人员都需要维护自己的本地(非修订版本控制的)文件副本。为避免git检测到这些文件中的更改,您还应该使用此命令:

  git update-index --assume-unchanged [路径] 

您可能想要做什么:(从 @瑞安泰勒答案



  1. git你想要你自己的独立版本的文件或文件夹。例如,您不想覆盖(或删除)
    生产/登台配置文件。

git update-index --skip-worktree<路径名称>


答案在这里URL: http://source.kohlerville.com / 2009/02 / untrack-files-in-git /


I have cloned a project that includes some .csproj files. I don't need/like my local csproj files being tracked by Git (or being brought up when creating a patch), but clearly they are needed in the project.

I have added *.csproj to my LOCAL .gitignore, but the files are already in the repo.

When I type git status, it shows my changes to csproj which I am not interested in keeping track of or submitting for patches.

How do I remove the "tracking of" these files from my personal repo (but keep them in the source so I can use them) so that I don't see the changes when I do a status (or create a patch)?

Is there a correct/canonical way to handle this situation?

解决方案

Just calling git rm --cached on each of the files you want to remove from revision control should be fine. As long as your local ignore patterns are correct you won't see these files included in the output of git status.

Note that this solution removes the files from the repository, so all developers would need to maintain their own local (non-revision controlled) copies of the file

To prevent git from detecting changes in these files you should also use this command:

git update-index --assume-unchanged [path]

What you probably want to do: (from below @Ryan Taylor answer)

  1. This is to tell git you want your own independent version of the file or folder. For instance, you don't want to overwrite (or delete) production/staging config files.

git update-index --skip-worktree <path-name>

The full answer is here in this URL: http://source.kohlerville.com/2009/02/untrack-files-in-git/

这篇关于如何停止跟踪并忽略Git中文件的更改?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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