在仓库目录下新建一个名为.gitignore的文件
.gitignore文件对其所在的目录及所在目录的全部子目录均有效
例:
#ignore eclipse project file忽略.classpath、.project 文件
.*
#ignore target directory忽略target目录
target/
# 忽略target文件和target目录
target
# 只忽略target目录,不忽略target文件
target/
# 只忽略target文件,不忽略target目录
target
!target/
# 只忽略当前路径下的target文件和目录,子目录的target忽略
/target
git忽略目录下的文件,保留目录的方法
假设target目录下有:
-hello.class
-world.class
保留target忽略*.class文件
在target目录下新建一个空文件.gitfake文件名随意
执行命令:git add log/.gitfake -f
<注>这里如果不加-f会出现错误:
$ git add target /.gitfake
The following paths are ignored by one of your .gitignore files:
target
Use -f if you really want to add them.
fatal: no files added
最后commit & push