Git的多人协作和分支处理测试
生活随笔
收集整理的這篇文章主要介紹了
Git的多人协作和分支处理测试
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
首先配置ssh密鑰
克隆項目
- 配置兩臺主機(一臺本地mac,一臺云服務器)通過這樣的方式模擬多人開發。
創建分支
[root@ ~/Git_test_多人協作和沖突合并/branch_test]$ ls README.md [root@ ~/Git_test_多人協作和沖突合并/branch_test]$ git branch * master [root@ ~/Git_test_多人協作和沖突合并/branch_test]$ git branch yun [root@ ~/Git_test_多人協作和沖突合并/branch_test]$ git branch * masteryun [root@ ~/Git_test_多人協作和沖突合并/branch_test]$轉移到分支并在分支添加項目
[root@ ~/branch_test]$ ls README.md [root@ ~/branch_test]$ git checkout yun 切換到分支 'yun' [root@ ~/branch_test]$ git branchmaster * yun [root@ ~/branch_test]$ ls README.md [root@ ~/branch_test]$ touch yun1.c [root@ ~/branch_test]$ ls README.md yun1.c [root@ ~/branch_test]$ git add yun1.c [root@ ~/branch_test]$ git commit -m "yun1.c"*** Please tell me who you are.Rungit config --global user.email "you@example.com"git config --global user.name "Your Name"to set your account's default identity. Omit --global to set the identity only in this repository.fatal: empty ident name not allowed要提交自己的用戶名和郵箱才可以繼續
- 提交完畢后
沖突測試
master
- 首先使用yun提交一段代碼
- 這是master的yun1.c文件就有了一段代碼
- 我們使用mac進行提交
沖突時我們要先git pull再git push
- git pull
- git diff 查看文件的不同
其他分支
yun 分支添加文字并提交
[root@ ~/branch_test]$ git branchmaster * yun [root@ ~/branch_test]$ ls README.md yun1.c [root@ ~/branch_test]$ vim yun1.c [root@ ~/branch_test]$ cat yun1.c yun hello[root@ ~/branch_test]$ git add yun1.c [root@ ~/branch_test]$ git commit -m "yun yun1.c" [yun 4d7c92c] yun yun1.c1 file changed, 1 insertion(+), 1 deletion(-) [root@ ~/branch_test]$ git push Counting objects: 5, done. Delta compression using up to 4 threads. Compressing objects: 100% (2/2), done. Writing objects: 100% (3/3), 278 bytes | 0 bytes/s, done. Total 3 (delta 0), reused 0 (delta 0) remote: remote: To create a merge request for yun, visit: remote: http://git.github.com/kouhaozhe/branch_test/merge_requests/new?merge_request%5Bsource_branch%5D=yun remote: To git@git.github.com:kouhaozhe/branch_test.git025a01e..4d7c92c yun -> yun [root@ ~/Git_test_多人協作和沖突合并/branch_test]$- 這時網頁已經有了我們提交的帶著,我們切換到另一臺機器
另一臺電腦除了自己創建的分支,看不見另一臺電腦創建的分支,這時使用命令
同步之后沒有yun這個分支,操作命令
切換另一臺主機創建的分支
Tips:
error: you need to resolve your current index first
khz:branch_test kouhz$ git reset --merge
khz:branch_test kouhz$ git checkout -b yun origin/yun
Branch ‘yun’ set up to track remote branch ‘yun’ from ‘origin’.
Switched to a new branch ‘yun’
在進行添加代碼
khz:branch_test kouhz$ cat yun1.c <<<<<<< HEAD hello world HELLO WORLD ======= yun hello >>>>>>> 4d7c92c5686128aa3c99c25f3dbfdbbd88f8cf5e khz:branch_test kouhz$ vim yun1.c khz:branch_test kouhz$ cat yun1.c yun hello hello world HELLO WORLDkhz:branch_test kouhz$ git add yun1.c khz:branch_test kouhz$ git commit -m "mac" [yun ae006aa] mac khz:branch_test kouhz$ git push origin yun Counting objects: 6, done. Delta compression using up to 4 threads. Compressing objects: 100% (4/4), done. Writing objects: 100% (6/6), 577 bytes | 577.00 KiB/s, done. Total 6 (delta 0), reused 0 (delta 0) remote: remote: To create a merge request for yun, visit: remote: http://git.github.com/kouhaozhe/branch_test/merge_requests/new?merge_request%5Bsource_branch%5D=yun remote: To git.github.com:kouhaozhe/branch_test.git4d7c92c..ae006aa yun -> yun切換到另一臺主機
- 進行git pull操作,結果失敗了!原因是沒有指定本地dev分支與遠程origin/dev分支的鏈接
- 我們按照提示進行操作
git branch --set-upstream-to=origin/ yun
git branch --set-upstream-to=origin/yun yun
這時操作就成功了
[root@ ~/branch_test]$ cat yun1.c yun hello [root@ ~/branch_test]$ git pull 更新 4d7c92c..ae006aa Fast-forwardyun1.c | 2 ++1 file changed, 2 insertions(+) [root@ ~/Git_test_多人協作和沖突合并/bra nch_test]$ cat yun1.c yun hello hello world HELLO WORLD如何一次性永久保存密碼
git config --global credential.helper store
總結
以上是生活随笔為你收集整理的Git的多人协作和分支处理测试的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 成都大熊猫繁育研究基地儿童票要求
- 下一篇: 男生无精子症的症状