如何让 git 忽略我的 csv 文件?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/33175721/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-19 11:28:00  来源:igfitidea点击:

How do I get git to ignore my csv files?

gitcsvgitignore

提问by Candic3

I want git to ignore my csv files. But, when I do git status, I see that the csv is in "Changes not staged for commit". But, I swear I added it to the .gitignore file a while ago. In fact, when I look at the .gitignorefile, I see that it is there!

我想让 git 忽略我的 csv 文件。但是,当我这样做时git status,我看到 csv 在"Changes not staged for commit". 但是,我发誓我不久前将它添加到 .gitignore 文件中。事实上,当我查看.gitignore文件时,我看到它就在那里!

*.csv

So, how to I get gitto ignore my csv's? The problem is that I want to be able to do git resetand git checkoutwithout having to worry about the csvfiles being overwritten in my working directory.

那么,如何git忽略我的 csv 呢?问题是我希望能够这样做git reset并且git checkout不必担心csv我的工作目录中的文件被覆盖。

采纳答案by Sharath Bhaskara

Looks like the problem is that, the csv files are already tracked in a commit before, so even though you add *.csvthe git will start tracking the previously tracked files.

看起来问题在于,csv 文件之前已经在提交中跟踪过,因此即使您添加*.csvgit 也会开始跟踪以前跟踪过的文件。

You can solve this using git rm --cachedoption, discussed in detail in this stackoverflow question

您可以使用git rm --cached选项解决此问题,在此 stackoverflow question中详细讨论

回答by KIT

It should add *.csvin your .gitignore file and after that use git rm --cached *.csvto remove all existing csv files from your git repository

它应该添加*.csv到您的 .gitignore 文件中,然后用于git rm --cached *.csv从您的 git 存储库中删除所有现有的 csv 文件