使用sourceTree提交代碼的時(shí)候,如果不添加忽略文件,經(jīng)常會(huì)有一些不必要的文件沖突,在sourceTree這個(gè)工具中設(shè)置了忽略文件以后,在提交的時(shí)候直接把.gitignore提交了以后,就不會(huì)有這樣的煩惱了.
1.設(shè)置→高級(jí)→編輯

image.png
2.在gitignore中添加需要忽略的文件.
配置語法:
以斜杠"/"開頭表示目錄;
以星號(hào)"*"通配多個(gè)字符;
以問號(hào)"?"通配單個(gè)字符
以方括號(hào)"[]"包含單個(gè)字符的匹配列表;
以嘆號(hào)"!"表示不忽略(跟蹤)匹配到的文件或目錄;
此外,git 對(duì)于.ignore 配置文件是按行從上到下進(jìn)行規(guī)則匹配的,意味著如果前面的規(guī)則匹配的范圍更大,則后面的規(guī)則將不會(huì)生效;然后點(diǎn)擊確定就好了。
3.最重要的一步
如果是第一次往倉庫中提交的話,設(shè)置完這個(gè)就可以看到效果.在提交的時(shí)候,這些文件都不會(huì)顯示在提交列表中.如果不是第一次提交,需要將之前倉庫中需要忽略的文件刪除掉,然后再提交.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