1,先檢出項目到一個文件夾
git clone
2,你檢出的項目默認是master,所以現在要查看遠程全部分支
git branch -a
-
- * master
- remotes/origin/HEAD -> origin/master
- remotes/origin/v1.2
- remotes/origin/master
- remotes/origin/v1.1
- remotes/origin/v1.0
3,切換分支
比如同時有三個人開發,1.2最早是基於1.0,但是由於項目未發布,1.0,1.1,1.2全部都在同時開發,現在想把1.0已經增加的功能先合並到1.2;
-
- 此時的步驟:check 1.2和1.0
git checkout v1.0
git checkout v1.2
-
- 然后再v1.2的分支基礎上執行merge
git merge v1.0
-
- 如果沒有報錯,那就直接提交代碼git push origin v1.2
- 如果報錯,基本是沖突了(比如):
-
- CONFLICT (content): Merge conflict in app/src/main/AndroidManifest.xml
- Auto-merging app/build.gradle
- CONFLICT (content): Merge conflict in app/build.gradle
- Automatic merge failed; fix conflicts and then commit the result.
-
- 你需要去到提示的文件里把git自動標注的版本沖突注釋掉,看你具體需要的功能進行刪減
- 然后把沖突的文件git add,和commit ,比如你有2個沖突文件,多文件add的時候直接空格隔開
-
- git add app/src/main/AndroidManifest.xml app/build.gradle
最后再commit
-
- git commit -m "解決2個分支之間的沖突"
4,提交代碼
git push origin v1.2
5,搞定
參考命令:
Git鼓勵大量使用分支:
查看分支:git branch
創建分支:git branch <name>
切換分支:git checkout <name>
創建+切換分支:git checkout -b <name>
合並某分支到當前分支:git merge <name>
刪除分支:git branch -d <name>
---------------------
作者:Ares Long
來源:CSDN
原文:https://blog.csdn.net/tmacsky/article/details/78795894