如何使用 Git GUI 忽略文件?
我在 .git 文件夹的文件夹中创建了一个 .gitignore 文件, 但在重新扫描存储库时我仍然收到我试图忽略的文件。
这是文件的内容。
# Ignored files
*.suo
*.user
bin
obj
*.pdb
*.cache
*_svn
*.svn
*.suo
*.user
*.build-res
TestResults
_ReSharper*
我做错了什么?该文件应该位于哪里?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
您需要确保您仍然看到的文件当前尚未提交或暂存。
如果您删除它们(
git rm
或git rm --cached
),然后将它们添加为私有文件,那么它们将被忽略。You need to make sure the file you are still seeing are not currently committed or staged.
If you remove them (
git rm
orgit rm --cached
), and then add them as private file, then they will be ignored.你的文件看起来不错。只要确保每行开头没有任何空格,我花了 4 个小时才找到我的 .gitignore 无法正常工作的原因;原因当然是剪切和粘贴问题,我在文件开头有一条垂直的空格线。
在确保您的 .gitignore 文件确实清除了您不想要的所有内容之前,您应该小心使用 git commit -a 。使用
git add *.cpp *.h
标记每个文件(或使用通配符),或者 - 就像我喜欢的那样 - 随着进度开发您的 .gitignore,并始终检查git status
提交之前的代码>。如果您想仔细检查 .gitignore 是否确实有效,尝试
这应该列出您当前忽略的所有文件。
要清除已经添加的文件(可能使用
git add .
,这是我们一开始就犯的错误 =]),您可以像 @VonC 说:要么运行 要么
清理
您无意中添加的所有文件的另一个选项是完全清理您的存储库,然后再次重新添加所有内容。如果你想清除暂存区中的所有内容,你可以运行
但记住不要运行
git add .
直到您确保 git status 仅列出存储库中您真正想要的文件。git 的另一个非常有用的事情是,使用通配符时它不需要文件路径。如果您列出了忽略的文件并发现您想要删除所有
*.suo
和*.log
文件,只需运行git 就会找到您的文件中的所有文件。与该签名匹配的存储库,无论它们位于树中的哪个位置。
Your file looks good. Just make sure you don't have any kind of whitespace at the beginning of each line, it took me 4 hours to find why my .gitignore wasn't working correctly; the reason was of course a cut'n'paste issue where I had a vertical line of spaces at the beginning of the file.
You should be careful with
git commit -a
before making sure that your .gitignore file really cleans out everything you don't want. Either mark each file (or use wildcards) withgit add *.cpp *.h
or - like I prefer - develop your .gitignore as you progress, and always check withgit status
before commiting.If you want to double-check that your .gitignore really works, try
This should list all the files that you are currently ignoring.
To clean out the files you've already added (probably using
git add .
, a mistake we all make in the beginning =]) you can do like @VonC said:either run
or
Another option of cleaning out all the files you've unintentionally added is to totally clean your repository, and then re-add everything again. If you want to clear out everything in the staging area, you can run
But remember to not run
git add .
Until you've made sure that git status only lists the files you really want in the repository.Another very useful thing with git is that it doesn't need paths to files when using wildcards. If you list your ignored files and see that you want to remove all
*.suo
and*.log
files, just runand git takes care of finding all the files in your repository that matches that signature, no matter where in the tree they are.
我尝试了多种方法来使其发挥作用,最终非常简单:
您必须首先提交 .gitignore!
此外,如果您使用 TortoiseGIT - GitEx 提交工具,还有一个选项可以编辑忽略的文件。
I tried multiple ways to get this to work and it was finally pretty simple:
You must commit the .gitignore first!
Also, if you use TortoiseGIT - GitEx Commit Tool, there is an option to edit ignored files.
您的位置是正确的。 .gitignore 应该位于 .git 文件夹所在的同一文件夹中。里面的文件看起来也正确。但是,我在顶部没有评论行..
You are locating it right. .gitignore should be at the same folder, where is .git folder located. File inside also looks correct. However, I dont have a comment line at the top..
当我看到这个时,我认为您忘记提交忽略文件。
When I look at this, I would think you forgot to commit your ignore file.
--rm 缓存解决方案都不适合我。该文件需要编码为 ASCII/ANSI。我也更改了行结尾,但仅此并没有解决问题。我找不到包含这些说明的网址(对不起,原始海报!)但这对我有用:
也可以,但我使用 Notepad++。
从 Windows 中的命令提示符或 git 命令提示符(无论您喜欢哪种),当您执行 git status 时,它不应显示 .gitignore 中的文件。
None of the --rm cached solutions worked for me. The file needs to be encoded as ASCII/ANSI. I changed the line endings as well, but that alone didn't fix it. I can't find the url that had these instructions(sorry, original poster!) but this worked for me:
also work, but I use Notepad++.
From the command prompt in windows or the git command prompt, whichever you like, when you do git status it should not show files in .gitignore.