[英]How do I .ignore files with Git GUI?
I have created a .gitignore file in the folder with the .git folder, but I still get the files I'm trying to ignore when doing a rescan of the repository. 我在.git文件夹的文件夹中创建了一个.gitignore文件,但在重新扫描存储库时,我仍然会收到我试图忽略的文件。
This is the content of the file. 这是文件的内容。
# Ignored files
*.suo
*.user
bin
obj
*.pdb
*.cache
*_svn
*.svn
*.suo
*.user
*.build-res
TestResults
_ReSharper*
What am I doing wrong? 我究竟做错了什么? where is the file suppose to be located?
假设位于何处?
You need to make sure the file you are still seeing are not currently committed or staged. 您需要确保您仍然看到的文件当前未提交或暂存。
If you remove them ( git rm
or git rm --cached
), and then add them as private file, then they will be ignored. 如果你删除它们(
git rm
或git rm --cached
),然后将它们添加为私有文件,那么它们将被忽略。
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;
只要确保你在每行的开头都没有任何空格,我花了4个小时才找到为什么我的.gitignore工作不正常; the reason was of course a cut'n'paste issue where I had a vertical line of spaces at the beginning of the file.
原因当然是cut'n'paste问题,我在文件的开头有一个垂直的空格行。
You should be careful with git commit -a
before making sure that your .gitignore file really cleans out everything you don't want. 在确保你的.gitignore文件真正清除你不想要的一切之前,你应该小心使用
git commit -a
。 Either mark each file (or use wildcards) with git add *.cpp *.h
or - like I prefer - develop your .gitignore as you progress, and always check with git status
before commiting. 使用
git add *.cpp *.h
标记每个文件(或使用通配符)或者 - 比如我更喜欢 - 在进度时开发你的.gitignore,并在提交前始终检查git status
。
If you want to double-check that your .gitignore really works, try 如果你想仔细检查你的.gitignore是否真的有用, 试试吧
git ls-files --others -i --exclude-standard
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 要清理你已经添加的文件(可能是使用
git add .
,我们在开头犯了一个错误=])你可以像@VonC那样说:要么运行
git rm <filename>
or 要么
git rm --cached <filename>
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
如果要清除暂存区域中的所有内容, 可以运行
git --rm cached .
But remember to not run git add .
但请记住不要运行
git add .
Until you've made sure that git status only lists the files you really want in the repository. 直到你确定git status只列出你真正想要的文件库。
Another very useful thing with git is that it doesn't need paths to files when using wildcards. git的另一个非常有用的功能是它在使用通配符时不需要文件路径。 If you list your ignored files and see that you want to remove all
*.suo
and *.log
files, just run 如果列出被忽略的文件并看到要删除所有
*.suo
和*.log
文件,只需运行即可
git rm --cached *.suo *.log
and git takes care of finding all the files in your repository that matches that signature, no matter where in the tree they are. 并且git负责查找存储库中与该签名匹配的所有文件,无论它们位于树中的哪个位置。
I tried multiple ways to get this to work and it was finally pretty simple: 我尝试了多种方法让它工作,最后很简单:
You must commit the .gitignore first! 你必须先提交.gitignore!
Also, if you use TortoiseGIT - GitEx Commit Tool, there is an option to edit ignored files. 此外,如果您使用TortoiseGIT - GitEx提交工具,则可以选择编辑被忽略的文件。
You are locating it right. 你找对了。 .gitignore should be at the same folder, where is .git folder located.
.gitignore应该位于同一个文件夹中,其中.git文件夹位于。 File inside also looks correct.
里面的文件也看起来正确。 However, I dont have a comment line at the top..
但是,我顶部没有评论专线..
当我看到这个时,我会认为你忘了提交你的忽略文件。
None of the --rm cached solutions worked for me. 没有--rm缓存解决方案适合我。 The file needs to be encoded as ASCII/ANSI.
该文件需要编码为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:
我找不到有这些说明的网址(对不起,原创海报!)但这对我有用:
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. 从windows或git命令提示符中的命令提示符,无论你喜欢什么,当你执行git status时,它不应该在.gitignore中显示文件。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.