配置全局. gitignore文件可以很好的解决多人开发的冲突问题
1.在home路径下创建ignore文件
cd ~/
touch .gitignore
vim .gitignore
2.将以下过滤代码粘贴进去 (也可以打卡文件夹 shift + command + .)显示隐藏文件 用文本编辑器打开粘贴
# Xcode
.DS_Store
## Build generated
build/
DerivedData/
## Various settings
*.pbxuser
!default.pbxuser
*.mode1v3
!default.mode1v3
*.mode2v3
!default.mode2v3
*.perspectivev3
!default.perspectivev3
xcuserdata/
## Other
*.moved-aside
*.xccheckout
*.xcworkspace
!default.xcworkspace
## Obj-C/Swift specific
*.hmap
*.ipa
*.dSYM.zip
*.dSYM
# CocoaPods
Pods
!Podfile
!Podfile.lock
# Carthage
Carthage/Build
# fastlane
fastlane/report.xml
fastlane/Preview.html
fastlane/screenshots
fastlane/test_output
# Code Injection
iOSInjectionProject/
上面已经含括了常用的过滤,下面是一些基本的可供参考
*.o,*.lo,*.la,*.al,.libs,*.so,*.so.[0-9]*,*.a,*.pyc,*.pyo,*.rej,*~,#*#,.#*,.*.swp,.DS_Store
3.执行全局gitignore配置将创建的.gitignore文件配置为默认的全局过滤文件
git config --global core.excludesfile ~/.gitignore
4.检查文件是否生效
cd ~/
la
vim .gitconfig
效果如下图会出现:
excludesfile = /Users/xiaobai/.gitignore
![](https://img.haomeiwen.com/i2066243/a01ed50fbe09cd7a.png)
4.以上就配置好了
已经提交了忽略文件的重置
方案一
1.因为可能在配置ignore文件之前已经把代码提交了,现在需要把不需要的代码撤回要进行以下操作:
git rm -r --cached . //这边有点
git add .
git commit -m "update .gitignore"
git push origin master
2.重新git clone url/ssh
cd 到目标文件
pod update /或者 pod update --no-repo-update
后者速度快,如果后者不行则用前者还不行 pod -repo update /pod install --verbose --no-repo-update
注意点
方案一
1).gitignore只能忽略那些原来没有被track的文件,如果某些文件已经被纳入了版本管理中,则修改.gitignore是无效的。
2)想要.gitignore起作用,必须要在这些文件不在暂存区中才可以,.gitignore文件只是忽略没有被staged(cached)文件,
对于已经被staged文件,加入ignore文件时一定要先从staged移除,才可以忽略。
方案二
逐个标记 在每个clone下来的仓库中手动设置不要检查特定文件的更改情况
git update-index --assume-unchanged PATH //在PATH处输入要忽略的文件
以上只是简单的介绍.gitignore文件的使用方法,为想快速继承的小伙伴们准备的,想要看原理可以参照以下链接gitIgnore详解。
网友评论