GIT 操作詳細步驟
1. clone代碼
命令: git clone git:mt8735_m0_v1.0.3
說明: 克隆下來的代碼, 默認為master分支,遠程分支為remote/origin/master。
HEAD指向當前所在的分支(master)。
remote/origin/master中,origin為默認的遠程機器名,master為遠程分支名稱。
圖示:
注:在包含“.git”的目錄中,執行以下命令
scp git:hooks/commit-msg .git/hooks/
2. 建立bug分支(比如mantis100用于修改mantis上的bug#100)
命令: git checkout -b mantis100
說明:命令執行完成后, 會自動創建并切換至mantis100分支,因此HEAD會指向此分支(mantis100)。
圖示:
3. 修改bug#100并在mantis100分支上進行提交
命令: git add, git commit
說明:在修改bug#100的過程中,服務器上會有新的提交(S4,S5)。
mantis100分支指針會隨著提交而移動,始終指當前分支的最后一次提交(L1,L2)
由于沒有直接在master分支提交,master指針不變。
remote/origin/master指針在(通過fetch, pull等同步命令)與服務器同步前始終不變。
圖示:
4. 使用fetch指令獲取服務器上的更新
命令: git fetch origin
說明:fetch只會把服務器上的更新拉取到本地,不會與本地的master分支進行合并。
remote/origin/master會始終指向獲取到的最后一個遠程修改。
圖示:
5. 切換至master分支
命令: git checkout master
說明:其實就是HEAD指針指向master, mantis100和master指針均不變
圖示:
6. 使用rebase命令更新master分支
命令: git rebase origin/master
說明:目的是使master分支與remote/origin/master分支保持一致, 為后面的cherry-pick做準備
由于master分支上沒有在本地提交過修改,因此這個指令不會導致合并動作, 僅將master分支的指針移動至remote/origin/master所指向的節點。
圖示:
7. 使用cherry-pick命令追加mantis100分支上的修改
命令: git cherry-pick L1,git cherry-pick L2
說明:有選擇性地將L1或L2追加到master分支的末尾,這部分被追加的修改將會被推送到服務器。
圖示:
8. 刪除mantis100分支
命令: git branch -d mantis100
說明:此時mantis100上的修改已經追加到master分支上準備push了,因此mantis100分支已經完成了它的歷史使命,可以刪除了。
不建議繼續在這個分支上進行開發, 否則會導致分支間的關聯過于復雜而產生各種依賴問題。
圖示:
9. 使用push命令推送修改至review服務器
命令: git push origin HEAD:refs/for/master
說明:master分支上,在remote/origin/master之后的修改將被推送至代碼審核服務器
注意:各個修改的change-id不能相同,否則會出錯。
注: 第5步至第7步也可以通過直接在mantis100分支上使用rebase指令來實現。基本思路為:
當remote/origin/master已經通過fetch命令更新了以后,在mantis100分支上:
1. 直接將mantis100分支的修改rebase到remote/origin/master,git rebase origin/master
2. 如果rebase過程中產生沖突,需要手動解決沖突并add修改后文件,再執行rebase –continue
3. 切換回master,并將master分支直接rebase到mantis100分支
4. 刪除mantis100分支。
來自:http://www.jianshu.com/p/60fac8b97465