常常我们在本地 git 仓库中管理的一部分文件不需要上传到远端仓库,毕竟我们提交的只是代码部分。一些第三方体积较大、一些无关紧要的文件,都是不需要上传到远端仓库的。所以说我们可以忽略掉,也就是常说的 .gitignore。最好的方式就是创建一份自己的 .gitignore 文件,然后把常用的忽略文件 copy 到上面就可以了。
就比如说下面的终端命令提示中,我们提交的部分包含了 Pods 中的三方代码,超过了 100MB 而导致提交失败。
wangzhongyao:eHighSpeed wangzhongyao$ git push origin master
Counting objects: 1538, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (1498/1498), done.
Writing objects: 100% (1538/1538), 156.55 MiB | 1.45 MiB/s, done.
Total 1538 (delta 218), reused 17 (delta 4)
remote: Resolving deltas: 100% (218/218), done.
remote: Powered by Gitee.com
remote: warning: Large files detected.
remote: error: File Pods/AMap3DMap/MAMapKit.framework/MAMapKit is 126.44 MB; this exceeds file size limit of 100.0 MB
remote: error: hook declined to update refs/heads/master
To gitee.com:yigaosu/eHighSpeed.git
! [remote rejected] master -> master (hook declined)
error: failed to push some refs to 'git@gitee.com:yigaosu/eHighSpeed.git'
所以:
① 创建自己的 .ignore 文件:
cd 到自己项目下,然后 touch .gitignore
② 配置 .ignore 文件,下面是我用到的需要忽略掉的部分文件:
# Xcode
.DS_Store
*.DS_Store
._.DS_Store
*/Lib/*
BPB/Classes/Lib/
profile
*.moved-aside
DerivedData
.idea/
*.hmap
*.xccheckout
*.xcworkspace
!default.xcworkspace
*.xcuserstate
project.xcworkspace
UserInterfaceState.xcuserstate
project.xcworkspace/
xcuserdata/
UserInterface.xcuserstate
#CocoaPods
Pods
Podfile
Podfile.lock
## Build generated
build/
DerivedData/
*/build/*
## Various settings
*.pbxuser
!default.pbxuser
*.mode1v3
!default.mode1v3
*.mode2v3
!default.mode2v3
*.perspectivev3
!default.perspectivev3
xcuserdata/
## Other
*.moved-aside
*.xcuserstate
## Obj-C/Swift specific
*.hmap
*.ipa
*.dSYM.zip
*.dSYM
再另外对上面的忽略文件做一下说明:
# 注释符
*.xxx 忽略以 xxx 结尾的文件
*/Lib/* 忽略 Lib 文件夹下的所有文件(不考虑 Lib 文件夹究竟在那里)
Podfile 直接忽略掉 Podfile 文件
基本上我在项目中用到的就是这些,不足之处欢迎大家提出补充。