git 未跟踪文件 - 如何忽略

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

git untracked files - how to ignore

gitversion-controldvcsgitignoregit-status

提问by JDesigns

When I run git status, I see the "Untracked files" section has many files (some with a "." extension.)

当我运行时git status,我看到“未跟踪的文件”部分有很多文件(有些带有“.”扩展名。)

I don't think I have to do anything, but it doesnt look good to see these files whenever I run git status. Is there any way to not to see these files?

我不认为我必须做任何事情,但是每次运行git status. 有没有办法看不到这些文件?

回答by wilhelmtell

Files that are "yours", files that no one else sees, write in .git/info/exclude.

“你的”文件,其他人看不到的文件,写在 .git/info/exclude 中。

For files that everyone else sees, write them down in .gitignore at the project top directory and then add and commit the .gitignore file.

对于其他人看到的文件,将它们写在项目顶级目录的 .gitignore 中,然后添加并提交 .gitignore 文件。

For example, your .gitignore might look like so:

例如,您的 .gitignore 可能如下所示:

*.o
.*.sw[op]
*~

回答by sam hocevar

You need to create one or several .gitignorefiles. They can be stored in git itself, or just kept local.

您需要创建一个或多个.gitignore文件。它们可以存储在 git 本身中,也可以只保存在本地。

回答by rambo

You can make git ignore all files that match a regular expression (like all files *.ext) by adding the line *.extin file .git/info/exclude.

您可以通过*.ext在 file 中添加行使 git 忽略所有匹配正则表达式的文件(如所有文件 *.ext).git/info/exclude

Added Abe Voelker's comment bellow to improve the answer:

在下面添加了 Abe Voelker 的评论以改进答案:

Note that this approach is local to your repository. If you ever clone it (e.g. share it with others), your ignore settings will not be pulled in.

请注意,此方法对于您的存储库是本地的。如果您曾经克隆过它(例如与他人共享),您的忽略设置将不会被拉入。

If you need to share the ignore settings, you should put it in .gitignorefiles

如果你需要分享忽略设置,你应该把它放在.gitignore文件中

回答by James Gregory

To ignore, use .gitignore, as Sam Hocevar said.

要忽略,请使用.gitignore,正如 Sam Hocevar 所说。

To delete, you'll probably want to do a git clean, which will clean up any files that aren't tracked by git. You might need to use the -fand -dswitches if you've got directories which aren't tracked.

要删除,您可能需要执行一个git clean,这将清除 git 未跟踪的所有文件。如果您有未跟踪的目录,则可能需要使用-f-d开关。

Be careful with git clean, it will delete things you haven't added to git yet!

小心git clean,它会删除你还没有添加到 git 的东西!

回答by eludom

If you want to do this globally all the time do

如果你想一直在全球范围内这样做

git config status.showuntrackedfiles no