git--
忽略某个⽂件
1.
修改
.gitignore
⽂件
在
git
中如果想忽略掉某个⽂件,不让这个⽂件提交到版本库中,可以使⽤修改
.gitignore
⽂件的⽅法。
举例:
.gitignore
⽂件内容如下:
# Android generated
bin/
gen/
classes/
gen-external-apklibs/
# Ant
local.properties
# Maven
target/
release.properties
# Eclipse
.classpath
.project
.externalToolBuilders/
.metadata
.settings
# IntelliJ
*.iml
*.ipr
*.iws
.idea/
out/
# Mac
.DS_Store
# gitignore
.gitignore
2.
使⽤命令
.gitignore
只能忽略那些原来没有被
track
的⽂件,如果某些⽂件已经被纳⼊了版本管理中,则修改
.gitignore
是⽆效的。
正确的做法是在每个
clone
下来的仓库中⼿动设置不要检查特定⽂件的更改情况。
git update-index --assume-unchanged FILE
在
FILE
处输⼊要忽略的⽂件。
如果要还原的话,使⽤命令:
git update-index --no-assume-unchanged FILE
3.
使⽤
.git/info/exclude
git
还提供了另⼀种
exclude
的⽅式来做同样的事情,不同的是
.gitignore
这个⽂件本⾝会提交到版本库中去。⽤来保存的是公共的需要排除
的⽂件。⽽
.git/info/exclude
这⾥设置的则是你⾃⼰本地需要排除的⽂件。
他不会影响到其他⼈。也不会提交到版本库中去。
举例:
# git ls-files --others --exclude-from=.git/info/exclude
# Lines that start with '#' are comments.
# For a project mostly in C, the following would be a good set of
# exclude patterns (uncomment them if you want to use them):
# *.[oa]
# *~
.gradle/
.idea/
.settings/
appcompat_v7/
bin/
build/
gen/
gradle/
out/
proguard/
ship/
target/
.classpath
.gitignore