最近公司项目代码转移到Gitlab,转移后发现过滤文件失效,这次就记录一下添加以及生效方法。
添加.gitignore
github可以下载各种语音对应的.gitignore文件,访问地址:https://github.com/github/gitignore
完善.gitignore
下载后我对文件进行了修改,我直接贴出来
# Xcode
#
# gitignore contributors: remember to update Global/Xcode.gitignore, Objective-C.gitignore & Swift.gitignore
.DS_Store
## User settings
xcuserdata/
## compatibility with Xcode 8 and earlier (ignoring not required starting Xcode 9)
*.xcscmblueprint
*.xccheckout
*.xcuserstate
## compatibility with Xcode 3 and earlier (ignoring not required starting Xcode 4)
build/
DerivedData/
*.moved-aside
*.pbxuser
!default.pbxuser
*.mode1v3
!default.mode1v3
*.mode2v3
!default.mode2v3
*.perspectivev3
!default.perspectivev3
## Obj-C/Swift specific
*.hmap
## App packaging
*.ipa
*.dSYM.zip
*.dSYM
# CocoaPods
#
# 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-check-the-pods-directory-into-source-control
Pods/
# Add this line if you want to avoid checking in source code from the Xcode workspace
# *.xcworkspace
# Carthage
#
# Add this line if you want to avoid checking in source code from Carthage dependencies.
# Carthage/Checkouts
Carthage/Build/
# fastlane
#
# It is recommended to not store the screenshots in the git repo.
# Instead, use fastlane to re-generate the screenshots whenever they are needed.
# For more information about the recommended setup visit:
# https://docs.fastlane.tools/best-practices/source-control/#source-control
fastlane/report.xml
fastlane/Preview.html
fastlane/screenshots/**/*.png
fastlane/test_output
# Code Injection
#
# After new code Injection tools there's a generated folder /iOSInjectionProject
# https://github.com/johnno1962/injectionforxcode
iOSInjectionProject/
.gitignore文件提交到仓库
Mac显示隐藏文件的快捷键:command+shift+.
终端显示当前隐藏文件命令:
cd 文件名
ls -a
查看.gitignore没问题(本人没看,谁知道我在修改文件名时变成了.gitignore.gitignore这样的格式)这进行提交
git add .gitignore
git commit -m "添加项目忽略文件"
git push
.gitignore生效
大家应该知道git规则,.gitignore只能忽略那些原来没有被track的文件,如果某些文件已经被纳入了版本管理中,则修改.gitignore是无效的
解决办法:我们可以先删除缓存路径,使用add .添加重新提交
git rm -r --cached .
git add .
git commit -m "update .gitignore"
git push