简体   繁体   中英

git untracked files - how to ignore

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

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?

Files that are "yours", files that no one else sees, write in.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.

For example, your.gitignore might look like so:

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

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

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 .

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

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

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

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 -f and -d switches if you've got directories which aren't tracked.

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

If you want to do this globally all the time do

git config status.showuntrackedfiles no

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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