Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
411 views
in Technique[技术] by (71.8m points)

git - 如何停止跟踪并忽略对Git中文件的更改?(How to stop tracking and ignore changes to a file in Git?)

I have cloned a project that includes some .csproj files.

(我已经克隆了一个包含一些.csproj文件的项目。)

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.

(我不需要/不喜欢我的本地csproj文件被Git跟踪(或在创建补丁时显示),但是显然在项目中需要它们。)

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

(我已经将*.csproj添加到我的LOCAL .gitignore ,但是文件已经在仓库中。)

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

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

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?

(有没有正确/规范的方法来处理这种情况?)

  ask by Joshua Ball translate from so

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Just calling git rm --cached on each of the files you want to remove from revision control should be fine.

(只需在要从版本控制中删除的每个文件上调用git rm --cached就可以了。)

As long as your local ignore patterns are correct you won't see these files included in the output of git status.

(只要您的本地忽略模式正确,您就不会在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检测到这些文件中的更改,您还应该使用以下命令:)

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

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

(您可能想做的是:(@Ryan Taylor答案下面))

  1. This is to tell git you want your own independent version of the file or folder.

    (这是告诉git您想要自己的文件或文件夹的独立版本。)

    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/

(完整的答案在以下URL中: http : //source.kohlerville.com/2009/02/untrack-files-in-git/)


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...