简体   繁体   English

git 未跟踪文件 - 如何忽略

[英]git untracked files - how to ignore

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 .我不认为我必须做任何事情,但是每当我运行git status时看到这些文件看起来并不好。 Is there any way to not to see these files?有没有办法不看到这些文件?

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:例如, your.gitignore 可能如下所示:

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

You need to create one or several .gitignore files.您需要创建一个或多个.gitignore文件。 They can be stored in git itself, or just kept local.它们可以存储在 git 本身中,或者只是保存在本地。

You can make git ignore all files that match a regular expression (like all files *.ext) by adding the line *.ext in file .git/info/exclude .您可以通过在文件.git/info/exclude中添加行*.ext使 git 忽略所有与正则表达式匹配的文件(如所有文件 *.ext)。

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 (eg 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 .gitignore files如果你需要共享忽略设置,你应该把它放在.gitignore文件中

To ignore, use .gitignore , as Sam Hocevar said.正如 Sam Hocevar 所说,要忽略,请使用.gitignore

To delete, you'll probably want to do a git clean , which will clean up any files that aren't tracked by git.要删除,您可能需要执行git clean ,这将清除 git 未跟踪的所有文件。 You might need to use the -f and -d switches if you've got directories which aren't tracked.如果您有未跟踪的目录,您可能需要使用-f-d开关。

Be careful with git clean , it will delete things you haven't added to git yet!小心git clean ,它会删除你还没有添加到 git 的东西!

If you want to do this globally all the time do如果您想一直在全球范围内执行此操作

git config status.showuntrackedfiles no

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

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