[Xcode] Source Code Management: Git Commit, Remote, Branch, Tag

Penny N.
4 min readJun 4, 2020

--

Photo by Scott Graham on Unsplash

Xcode讓使用Git管理Xcode project的source code變得簡單,不再需要透過terminal輸入指令來操作。

No Working Copies

如果專案沒有使用Git管理專案,在Navigation Pane的部分會顯示No Working Copies。

Create repository

在建立專案時,可以順便為專案建立Git repository。

不過如果忘了也沒關係,可以從 Menu > Source Control > Create Git Repositories建立。

Commit

Commit功能就像是電腦定期備份一樣,透過Menu > Source Control > Commit可以在電腦裡備份目前的code,之後如果不小心搞砸了自己的code,可以透過commit的紀錄回復到之前的狀態。

Commit時留下的comment可以幫助你和其他人了解這次commit做了什麼更動。

Remote

之前透過commit備份,只有將備份存在自己的電腦裡,remote則是可以將檔案存在其他平台,例如Github。

要把檔案傳到Github,首先要有Github帳號,並且在Xcode > Preference > Accounts裡設定帳號。

在commit時勾選Push to Remote就可以順便傳到Github上。

Push

如果在commit時忘了勾選Push to Remote,也可以透過Menu > Source Control > Push將檔案傳到Github上。

Tag

Tag可以用於發布不同版本的管理。在Navigation Pane可以進行tag設定。

從Right click > Tag “branchName” 可以新增tag。

如果沒有使用tag,在Github上永遠只能抓到最新的commit版本。但如果使用Tag,就可以抓到過去不同版本的檔案。

例如幾經改版的Facebook SDK,透過tag就可以抓到不同版本的檔案。

Branch

有時想嘗試不同寫法時,就可以用到branch功能建立分支。branch上程式碼的更動,不會影響到其他的分支。

若想回到Master或去到其他分支,可以透過Right Click > Check Out。

--

--

Penny N.
Penny N.

Written by Penny N.

A passionate self-taught  iOS developer. Write to record my learning and share the knowledge

No responses yet