# 如何在已建立的iOS專案忽略git已經紀錄的Pods?
###### tags: `iOS`
## 情況
接到一個舊案子,可能因為這案子的人對git的操作不熟悉,因此可能有使用git,但是沒有加入gitignore,那我們要如何幫舊案加入呢?因為Pods可以直接透過Pod install來安裝,因此希望不要上傳。
## 建立 .gitignore
#### 目標:
在專案資料夾內建立一個.gitignore檔案,並在.gitignore內加入哪些要忽略的檔案,讓git時可以自動忽略
#### 作法:
進入[gitignore.io](https://www.toptal.com/developers/gitignore)
輸入swift然後搜尋,如下圖所示(也可以輸入其他語言)

找到
```
# Pods/
```
並把#註解拿掉 (其他也有想忽略的也一併把#拿掉)
可以得到下面的程式碼
然後複製起來,等等會貼到.gitignore檔內
```
# Created by https://www.toptal.com/developers/gitignore/api/swift
# Edit at https://www.toptal.com/developers/gitignore?templates=swift
### Swift ###
# 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
## 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
## Playgrounds
timeline.xctimeline
playground.xcworkspace
# Swift Package Manager
# Add this line if you want to avoid checking in source code from Swift Package Manager dependencies.
# Packages/
# Package.pins
# Package.resolved
# *.xcodeproj
# Xcode automatically generates this directory with a .xcworkspacedata file and xcuserdata
# hence it is not needed unless you have added a package configuration file to your project
# .swiftpm
.build/
# 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/
# Accio dependency management
Dependencies/
.accio/
# 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/
# End of https://www.toptal.com/developers/gitignore/api/swift
```
開啟終端機
```linux
cd YourProjectFolder //進入你的資料夾
vi .gitignore //建立.gitignore檔案
```
這時候會進入vi編輯器
點擊字母a進入編輯模式
將剛剛的程式碼貼上
完成後輸入:wq <-這是vi的指令,詳情自己查
先進行一次commit
```
git add .
git commit -m "add gitignore"
```
這樣就完成加入gitignore
## 移除原本的pod cache
```
git rm -r --cached . //移除原本的cache
git add .
git commit -m ".gitignore is now working"
```
這樣子就不會再將Pods資料夾內的檔案上傳了
如果有任何問題歡迎與我聯繫
謝謝