四、Git多人开发:不同人修改了同文件的相同区域如何处理?
生活随笔
收集整理的這篇文章主要介紹了
四、Git多人开发:不同人修改了同文件的相同区域如何处理?
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
@Author:Runsen
不同人修改了同文件的相同區域如何處理?
現在小A發現小B在h1修改自己的代碼,非常的生氣,決定改回來。小B也覺得不好意思,于是也決定改回來。
小B在小A之前就把User.html改回了小A,不然給小A罵死。
maoli@ubuntu:~/B/muli_person_test$ vim user.html ##### <html><head>用戶</head><body><h1>這是小A開發的User.html</h1></body> </html> maoli@ubuntu:~/B/muli_person_test$ vim user.html maoli@ubuntu:~/B/muli_person_test$ git commit -m "XXX" [dev 1d75f13] XXX1 file changed, 1 insertion(+), 1 deletion(-) maoli@ubuntu:~/B/muli_person_test$ git push Delta compression using up to 4 threads. 壓縮對象中: 100% (3/3), 完成. 寫入對象中: 100% (3/3), 274 bytes | 0 bytes/s, 完成. Total 3 (delta 2), reused 0 (delta 0) remote: Powered by GITEE.COM [GNK-5.0] To https://gitee.com/MaoliRUNsen/muli_person_testdcff9e8..1d75f13 dev -> dev這個時候,小B已經將之前的錯誤修改了,可是小A不知道。發現小B將自己的成果占為己用,真的很生氣,于是趕緊去改下。
YIUYE@DESKTOP-5EEO47M MINGW64 ~/Desktop/A/muli_person_test (A) $ cat user.html <html><head>用戶</head><body><h1>這是小B開發的User.html</h1></body> </html> YIUYE@DESKTOP-5EEO47M MINGW64 ~/Desktop/A/muli_person_test (A) $ vim user.html <html><head>用戶</head><body><h1>這是小B開發的User.html,小B你真的不要臉</h1></body> </html>YIUYE@DESKTOP-5EEO47M MINGW64 ~/Desktop/A/muli_person_test (A) $ git add user.htmlYIUYE@DESKTOP-5EEO47M MINGW64 ~/Desktop/A/muli_person_test (A) $ git commit -m "小B真的不要臉" [A c096b6a] 小B真的不要臉1 file changed, 1 insertion(+), 1 deletion(-)YIUYE@DESKTOP-5EEO47M MINGW64 ~/Desktop/A/muli_person_test (A) $ git checkout dev Switched to branch 'dev' Your branch is behind 'origin/dev' by 1 commit, and can be fast-forwarded.(use "git pull" to update your local branch)YIUYE@DESKTOP-5EEO47M MINGW64 ~/Desktop/A/muli_person_test (dev) $ git merge A Updating d23e309..c096b6a Fast-forwarduser.html | 10 +++++-----1 file changed, 5 insertions(+), 5 deletions(-)YIUYE@DESKTOP-5EEO47M MINGW64 ~/Desktop/A/muli_person_test (dev) $ git pushTo https://gitee.com/MaoliRUNsen/muli_person_test! [rejected] dev -> dev (fetch first) error: failed to push some refs to 'https://gitee.com/MaoliRUNsen/muli_person_test' hint: Updates were rejected because the remote contains work that you do hint: not have locally. This is usually caused by another repository pushing hint: to the same ref. You may want to first integrate the remote changes hint: (e.g., 'git pull ...') before pushing again. hint: See the 'Note about fast-forwards' in 'git push --help' for details.一樣報錯了,原因大家想想。就是沒有pull,因為B提交了代碼,A的遠端并不同步。
YIUYE@DESKTOP-5EEO47M MINGW64 ~/Desktop/A/muli_person_test (dev) $ git pull remote: Enumerating objects: 5, done. remote: Counting objects: 100% (5/5), done. remote: Compressing objects: 100% (3/3), done. remote: Total 3 (delta 2), reused 0 (delta 0), pack-reused 0 Unpacking objects: 100% (3/3), done. From https://gitee.com/MaoliRUNsen/muli_person_testdcff9e8..1d75f13 dev -> origin/dev Auto-merging user.html CONFLICT (content): Merge conflict in user.html Automatic merge failed; fix conflicts and then commit the result.于是小A去pull,發現了出現CONFLICT (content): Merge conflict in user.html,這個的意思就是內容沖突,
在下圖就很明顯看到了小B改了代碼,可能小B知道錯了,以為小A不知道。小A看了下,就算了。
改回之前的代碼。
最后查看下git status,只需要使用git commit就可以解決沖突。
YIUYE@DESKTOP-5EEO47M MINGW64 ~/Desktop/A/muli_person_test (dev|MERGING) $ git status On branch dev Your branch and 'origin/dev' have diverged, and have 1 and 1 different commits each, respectively.(use "git pull" to merge the remote branch into yours) You have unmerged paths.(fix conflicts and run "git commit")Unmerged paths:(use "git add <file>..." to mark resolution)both modified: user.htmlno changes added to commit (use "git add" and/or "git commit -a")YIUYE@DESKTOP-5EEO47M MINGW64 ~/Desktop/A/muli_person_test (dev|MERGING) $ git commit -am "解決沖突" [dev d613e8f] 解決沖突這個時候同文件的相同區域產生的沖突就解決了。查看Git的狀態,就可以提交了。
YIUYE@DESKTOP-5EEO47M MINGW64 ~/Desktop/A/muli_person_test (dev) $ git status On branch dev Your branch is ahead of 'origin/dev' by 2 commits.(use "git push" to publish your local commits) nothing to commit, working directory cleanYIUYE@DESKTOP-5EEO47M MINGW64 ~/Desktop/A/muli_person_test (dev) $ git push Counting objects: 4, done. Delta compression using up to 12 threads. Compressing objects: 100% (4/4), done. Writing objects: 100% (4/4), 580 bytes | 0 bytes/s, done. Total 4 (delta 1), reused 0 (delta 0) remote: Powered by GITEE.COM [GNK-5.0] To https://gitee.com/MaoliRUNsen/muli_person_test1d75f13..d613e8f dev -> dev總結
以上是生活随笔為你收集整理的四、Git多人开发:不同人修改了同文件的相同区域如何处理?的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 机动车驾驶证分扣完了怎么办
- 下一篇: 五、Git多人开发:同时变更了文件名和文