简体   繁体   English

如何从IDE中停止跟踪git中的文件夹/文件

[英]How to stop tracking folder / files in git from IDE

I use PyCharm as my IDE and I love it. 我使用PyCharm作为我的IDE,我喜欢它。 I use git as my version control system. 我使用git作为我的版本控制系统。 I use it from within PyCharm (I don't know how to use it effectively any other way). 我在PyCharm中使用它(我不知道如何以任何其他方式有效地使用它)。 Every once in a while, I will want to stop tracking a file in git . 每隔一段时间,我就会想停止在git跟踪一个文件。 Whether I just don't want to track it anymore, or some .xml file somehow got added to the git list that always changes. 我是否只是不想再跟踪它,或者某些.xml文件以某种方式添加到总是更改的git列表中。

Is it true that there is no straitforward way to stop tracking a file or folder in git? 是不是没有直接的方法来停止跟踪git中的文件或文件夹? The methods I have found seem like I am spending way too much time to do something that I would think should be simple? 我发现的方法看起来好像花了太多时间做一些我认为应该简单的事情?

First thing I always do is add them to the .gitignore file but that doesn't help after the fact. 我经常做的第一件事是将它们添加到.gitignore文件中,但事后并没有帮助。

The two steps to stop tracking a file that you have been tracking are: 停止跟踪您一直跟踪的文件的两个步骤是:

  1. Add the file to the .gitignore 将文件添加到.gitignore
  2. git rm --cached [file name]

I do not know how to do that from within PyCharm , however. 但是,我不知道如何从PyCharm做到这一点。

I am also working with .gitignore to create rules to ignore files and is working perfectly fine within Eclipse and without any IDE. 我也在使用.gitignore来创建忽略文件的规则,并且在Eclipse中完全正常工作,没有任何IDE。

In general there are some rules to define. 通常,有一些规则要定义。 Furthermore if you add a rule later and git already track the file you want to ignore, this will not work and you should use a special command to fix that. 此外,如果您稍后添加规则并且git已经跟踪了您要忽略的文件,这将无法工作,您应该使用特殊命令来解决该问题。

In specific according to this site : 具体根据这个网站

If you already have a file checked in, and you want to ignore it, Git will not ignore the file if you add a rule later. 如果您已经签入了一个文件,并且想要忽略它,那么如果稍后添加规则,Git将不会忽略该文件。 In those cases, you must untrack the file first, by running the following command in your terminal: 在这些情况下,您必须首先在终端中运行以下命令来解除文件:

git rm --cached 

Open the Version Control tool window (Alt+9) and switch to the Local Changes tab. 打开“版本控制”工具窗口(Alt + 9)并切换到“本地更改”选项卡。 Click the Configure Ignored Files icon, and press the + sign to add files/folders that you want ignored. 单击“配置忽略的文件”图标,然后按+号添加要忽略的文件/文件夹。 While this will work in the IDE, it is not the same as adding them in the .gitignore file. 虽然这可以在IDE中使用,但它与在.gitignore文件中添加它们不同。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM