有时候接手的项目或者创建项目忘记创建.gitignore 文件,每次分支操作都很痛苦。可通过下面方式重新加入
1、在项目一级目录下添加gitignore文件
git命令:vi .gitignore
2.输入忽略的文件:
常用的github有总结:https://github.com/github/gitignore
Object-c我试了差一个,自己用的:
# Xcode
#
# gitignore contributors: remember to update Global/Xcode.gitignore, Objective-C.gitignore & Swift.gitignore
## User settings
xcuserdata/
## compatibility with Xcode 8 and earlier (ignoring not required starting Xcode 9)
*.xcscmblueprint
*.xccheckout
*.DS_Store
## 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/
3、因为忽略文件已经加入项目中,此时并不能生效,需要清空缓存,执行如下命令提交代码即可:
#add .gitignore
#查看状态,是否忽略了指定的文件?
$ git status --ignored #查看状态,包括忽略的文件
#让其对已经跟踪的文件也起作用
$ git rm -r --cached . #清除缓存 -r 表示递归删除(如果有文件夹的话) . 表示所有文件
#查看一下具体效果
$ git status --ignored
$ git add . #重新trace file
$ git commit -m "update .gitignore" #提交和注释