Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

【20170326】.gitignore 文件不起作用 #84

Closed
zhongxia245 opened this issue Mar 26, 2017 · 0 comments
Closed

【20170326】.gitignore 文件不起作用 #84

zhongxia245 opened this issue Mar 26, 2017 · 0 comments

Comments

@zhongxia245
Copy link
Owner

Git中.gitignore文件不起作用的解决以及Git中的忽略规则介绍

在Studio里使用Git管理代码的过程中,可以修改.gitignore文件中的标示的方法来忽略开发者想忽略掉的文件或目录,如果没有.gitignore文件,可以自己手工创建。在.gitignore文件中的每一行保存一个匹配的规则例如:

此为注释 – 将被 Git 忽略

*.a       # 忽略所有 .a 结尾的文件
!lib.a    # 但 lib.a 除外
/TODO     # 仅仅忽略项目根目录下的 TODO 文件,不包括 subdir/TODO
build/    # 忽略 build/ 目录下的所有文件
doc/*.txt # 会忽略 doc/notes.txt 但不包括 doc/server/arch.txt

在填写忽略文件的过程中,我发现在Android Studio里面,.gitignore中已经标明忽略的文件目录下的文件,当我想git push的时候还会出现在push的目录中,原因是因为在Studio的git忽略目录中,新建的文件在git中会有缓存,如果某些文件已经被纳入了版本管理中,就算是在.gitignore中已经声明了忽略路径也是不起作用的,这时候我们就应该先把本地缓存删除,然后再进行git的push,这样就不会出现忽略的文件了。git清除本地缓存命令如下:

git rm -r --cached .
git add .
git commit -m 'update .gitignore'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant