使用sourceTree提交代码的时候,如果不添加忽略文件,经常会有一些不必要的文件冲突,在sourceTree这个工具中设置了忽略文件以后,在提交的时候直接把.gitignore提交了以后,就不会有这样的烦恼了.
1.设置→高级→编辑

image.png
2.在gitignore中添加需要忽略的文件.
配置语法:
以斜杠"/"开头表示目录;
以星号"*"通配多个字符;
以问号"?"通配单个字符
以方括号"[]"包含单个字符的匹配列表;
以叹号"!"表示不忽略(跟踪)匹配到的文件或目录;
此外,git 对于.ignore 配置文件是按行从上到下进行规则匹配的,意味着如果前面的规则匹配的范围更大,则后面的规则将不会生效;然后点击确定就好了。
3.最重要的一步
如果是第一次往仓库中提交的话,设置完这个就可以看到效果.在提交的时候,这些文件都不会显示在提交列表中.如果不是第一次提交,需要将之前仓库中需要忽略的文件删除掉,然后再提交.gitignore文件.
.gitignore文件配置
# macOS
.DS_Store
# Xcode
build/
*.pbxuser
!default.pbxuser
*.mode1v3
!default.mode1v3
*.mode2v3
!default.mode2v3
*.perspectivev3
!default.perspectivev3
xcuserdata/
*.xccheckout
profile
*.moved-aside
DerivedData
*.hmap
*.ipa
Example/Pods
Example/Tests
# Bundler
.bundle
# Add this line if you want to avoid checking in source code from Carthage dependencies.
# Carthage/Checkouts
Carthage/Build
# We recommend against adding the Pods directory to your .gitignore. However
# you should judge for yourself, the pros and cons are mentioned at:
# https://guides.cocoapods.org/using/using-cocoapods.html#should-i-ignore-the-pods-directory-in-source-control
#
# Note: if you ignore the Pods directory, make sure to uncomment
# `pod install` in .travis.yml
#
# 忽略Pods
Pods/
Podfile.lock
# 忽略 组件化里面的Pods
Example/Pods/
Example/Podfile.lock