如何从 Intellij 中的 git 存储库中取消跟踪文件

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/21703565/
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 09:43:10  来源:igfitidea点击:

How can I untrack a file from a git repository in Intellij

gitintellij-idea

提问by H?i Phong

I'm having a tracked file in git but now I don't want to track it anymore (I don't want it to show up from the next commit but I still want to have it inside the folder).

我在 git 中有一个被跟踪的文件,但现在我不想再跟踪它(我不希望它从下一次提交中显示出来,但我仍然想把它放在文件夹中)。

In the Changestool window I have set that file as ignoredin Configured Ignored Filesbut somehow when I change that file, the changes still shows up in the change list?

Changes工具窗口中,我已将该文件设置为ignoredinConfigured Ignored Files但不知何故,当我更改该文件时,更改仍然显示在更改列表中?

回答by Vlad Nikitin

As of 2017.3.4, you cannot use the IDEA GUI to perform this command, it must be done from the command line or another tool.

自 2017.3.4 起,您无法使用 IDEA GUI 执行此命令,必须通过命令行或其他工具执行。

From console:

从控制台:

git rm --cached file
git commit -m'file removed'
echo 'file' >> .gitignore

回答by Erijk

IntelliJ doesn't allow you to untrack added files, but you quit easily can get to the same result as follows:

IntelliJ 不允许您取消跟踪添加的文件,但您轻松退出可以获得相同的结果,如下所示:

  1. In IntelliJ open the Version ControlTool Window
  2. In the Local Changestab: create a new change list (do NOT make it active)
  3. You can add all the files you would not want to commit to this new changelist.
  4. Commit and push only the other changelist(s)
  1. 在 IntelliJ 中打开Version Control工具窗口
  2. Local Changes选项卡中:创建一个新的更改列表(不要激活它)
  3. 您可以将所有不想提交的文件添加到这个新的更改列表中。
  4. 仅提交和推送其他更改列表

Like so you don't have to botter about (not) adding files. You can add all files and drag 'm into the new changelist if you don't want to commit these files.

像这样,您不必为(不)添加文件而烦恼。如果您不想提交这些文件,您可以添加所有文件并将 'm 拖到新的更改列表中。

Be aware though, when also using git cli, the files are still added to the working directory and will be taken into account when committing. Use the other answers on this page.

但是请注意,当还使用 git cli 时,这些文件仍会添加到工作目录中,并且在提交时会被考虑在内。使用此页面上的其他答案。

回答by Hossein Rezaei

in WebStorm 2018.2.1 you can do it like this: in version control tab right click unversioned files and ignore file

在 WebStorm 2018.2.1 中,您可以这样做:在版本控制选项卡中右键单击未版本化的文件并忽略文件