技术这点事——Git忽略某个文件

方法一:修改项目根目录下的.gitignore文件,排除的是公共的需要排除的文件,会被提交到版本库

.settings/*
target/*
*/.settings/*
*/target/*
.idea/*
*/.project
*/.classpath
.project
.classpath

# Intellij
*.iml
*/*.iml

看最后两个配置,这里我们排除了当前(.gitignore)目录下的以.iml为后缀的文件,以及当前目录下的所有文件夹中的.iml后缀的文件

方法二:修改.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]
# *~

*.iml

你可能感兴趣的:(技术这点事)