简体   繁体   中英

Git: How to ignore files on Windows?

I create .gitignore in folder with my repository near .git

project
--.git
--.gitignore
--Source
----tmp
----scr

But git doesn t see it, wouldn t ignore files in .gitignore

My .gitignore file:

*.tmp
*~
*.pdb
*.user
*.suo
Sources/tmp

What`s wrong?

Up: I created new repositiry, add .gitignore before init commit - it work! But if I add in old repository it doesn`t...

The problem is that you're specifying glob syntax when the default syntax for git is regex.

Try this instead:

.*\.tmp
.*~
.*\.pdb
.*\.user
.*\.suo
Sources\/tmp

What you have should work, though your directory listing has Source/ while your .gitignore has Sources/ .

The one thing that springs to mind is that the line endings might not be what git is expecting.

Also, as tmp is a directory, usually a trailing '/' is used:

Source/tmp/

Finally, you can also create a .gitignore in Source/ with the line:

tmp/ instead of having it in the top directory.

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