当前位置:   article > 正文

Git 【.gitignore】_提交git时,.gitignore要提交吗

提交git时,.gitignore要提交吗

常常我们在本地 git 仓库中管理的一部分文件不需要上传到远端仓库,毕竟我们提交的只是代码部分。一些第三方体积较大、一些无关紧要的文件,都是不需要上传到远端仓库的。所以说我们可以忽略掉,也就是常说的 .gitignore。最好的方式就是创建一份自己的 .gitignore 文件,然后把常用的忽略文件 copy 到上面就可以了。


就比如说下面的终端命令提示中,我们提交的部分包含了 Pods 中的三方代码,超过了 100MB 而导致提交失败。

  1. wangzhongyao:eHighSpeed wangzhongyao$ git push origin master
  2. Counting objects: 1538, done.
  3. Delta compression using up to 4 threads.
  4. Compressing objects: 100% (1498/1498), done.
  5. Writing objects: 100% (1538/1538), 156.55 MiB | 1.45 MiB/s, done.
  6. Total 1538 (delta 218), reused 17 (delta 4)
  7. remote: Resolving deltas: 100% (218/218), done.
  8. remote: Powered by Gitee.com
  9. remote: warning: Large files detected.
  10. remote: error: File Pods/AMap3DMap/MAMapKit.framework/MAMapKit is 126.44 MB; this exceeds file size limit of 100.0 MB
  11. remote: error: hook declined to update refs/heads/master
  12. To gitee.com:yigaosu/eHighSpeed.git
  13. ! [remote rejected] master -> master (hook declined)
  14. error: failed to push some refs to 'git@gitee.com:yigaosu/eHighSpeed.git'


所以:

① 创建自己的 .ignore 文件:

cd 到自己项目下,然后 touch .gitignore


② 配置 .ignore 文件,下面是我用到的需要忽略掉的部分文件:

  1. # Xcode
  2. .DS_Store
  3. *.DS_Store
  4. ._.DS_Store
  5. */Lib/*
  6. BPB/Classes/Lib/
  7. profile
  8. *.moved-aside
  9. DerivedData
  10. .idea/
  11. *.hmap
  12. *.xccheckout
  13. *.xcworkspace
  14. !default.xcworkspace
  15. *.xcuserstate
  16. project.xcworkspace
  17. UserInterfaceState.xcuserstate
  18. project.xcworkspace/
  19. xcuserdata/
  20. UserInterface.xcuserstate
  21. #CocoaPods
  22. Pods
  23. Podfile
  24. Podfile.lock
  25. ## Build generated
  26. build/
  27. DerivedData/
  28. */build/*
  29. ## Various settings
  30. *.pbxuser
  31. !default.pbxuser
  32. *.mode1v3
  33. !default.mode1v3
  34. *.mode2v3
  35. !default.mode2v3
  36. *.perspectivev3
  37. !default.perspectivev3
  38. xcuserdata/
  39. ## Other
  40. *.moved-aside
  41. *.xcuserstate
  42. ## Obj-C/Swift specific
  43. *.hmap
  44. *.ipa
  45. *.dSYM.zip
  46. *.dSYM


再另外对上面的忽略文件做一下说明:

#   注释符

*.xxx   忽略以 xxx 结尾的文件

*/Lib/*   忽略 Lib 文件夹下的所有文件(不考虑 Lib 文件夹究竟在那里)

Podfile   直接忽略掉 Podfile 文件


基本上我在项目中用到的就是这些,不足之处欢迎大家提出补充。

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/Cpp五条/article/detail/613626
推荐阅读
相关标签
  

闽ICP备14008679号