您好,登錄后才能下訂單哦!
今天小編給大家分享一下Git沖突如何處理的相關知識點,內容詳細,邏輯清晰,相信大部分人都還太了解這方面的知識,所以分享這篇文章給大家參考一下,希望大家閱讀完這篇文章后有所收獲,下面我們一起來了解一下吧。
Jerry 正在wchar_support分支上工作。他更改了函數的名稱,并在測試之后提交了他的更改。
[jerry@CentOS src]$ git branch master * wchar_support [jerry@CentOS src]$ git diff
上面的命令產生以下結果
diff --git a/src/string_operations.c b/src/string_operations.c index 8fb4b00..01ff4e0 100644--- a/src/string_operations.c +++ b/src/string_operations.c @@ -1,7 +1,7 @@#include <stdio.h>#include <wchar.h>-size_t w_strlen(const wchar_t *s) +size_t my_wstrlen(const wchar_t *s) { const wchar_t *p = s;
在驗證代碼后,他提交了他的更改。
[jerry@CentOS src]$ git status -s M string_operations.c [jerry@CentOS src]$ git add string_operations.c [jerry@CentOS src]$ git commit -m 'Changed function name'[wchar_support 3789fe8] Changed function name1 files changed, 1 insertions(+), 1 deletions(-) [jerry@CentOS src]$ git push origin wchar_support
上述命令將產生以下結果
Counting objects: 7, done. Compressing objects: 100% (4/4), done. Writing objects: 100% (4/4), 409 bytes, done. Total 4 (delta 1), reused 0 (delta 0) To gituser@git.server.com:project.git 64192f9..3789fe8 wchar_support -> wchar_support
同時在主分支中,Tom 也更改了相同函數的名稱,并將他的更改推送到主分支。
[tom@CentOS src]$ git branch * master [tom@CentOS src]$ git diff
上面的命令產生以下結果
diff --git a/src/string_operations.c b/src/string_operations.c index 8fb4b00..52bec84 100644--- a/src/string_operations.c +++ b/src/string_operations.c @@ -1,7 +1,8 @@#include <stdio.h>#include <wchar.h>-size_t w_strlen(const wchar_t *s) +/* wide character strlen fucntion */+size_t my_wc_strlen(const wchar_t *s) { const wchar_t *p = s;
在驗證 diff 之后,他提交了他的更改。
[tom@CentOS src]$ git status -s M string_operations.c [tom@CentOS src]$ git add string_operations.c [tom@CentOS src]$ git commit -m 'Changed function name from w_strlen to my_wc_strlen'[master ad4b530] Changed function name from w_strlen to my_wc_strlen1 files changed, 2 insertions(+), 1 deletions(-) [tom@CentOS src]$ git push origin master
上述命令將產生以下結果
Counting objects: 7, done. Compressing objects: 100% (4/4), done. Writing objects: 100% (4/4), 470 bytes, done. Total 4 (delta 1), reused 0 (delta 0) To gituser@git.server.com:project.git 64192f9..ad4b530 master -> master
在wchar_support分支上,Jerry 為寬字符串實現了 strchr 函數。測試后,他提交并將他的更改推送到wchar_support分支。
[jerry@CentOS src]$ git branch master * wchar_support [jerry@CentOS src]$ git diff
上面的命令產生以下結果
diff --git a/src/string_operations.c b/src/string_operations.c index 01ff4e0..163a779 100644--- a/src/string_operations.c +++ b/src/string_operations.c @@ -1,6 +1,16 @@#include <stdio.h>#include <wchar.h>+wchar_t *my_wstrchr(wchar_t *ws, wchar_t wc) + { + while (*ws) { + if (*ws == wc) + return ws; + ++ws; + } + return NULL; + } +size_t my_wstrlen(const wchar_t *s) { const wchar_t *p = s;
在驗證之后,他提交了他的更改。
[jerry@CentOS src]$ git status -s M string_operations.c [jerry@CentOS src]$ git add string_operations.c [jerry@CentOS src]$ git commit -m 'Addded strchr function for wide character string'[wchar_support 9d201a9] Addded strchr function for wide character string1 files changed, 10 insertions(+), 0 deletions(-) [jerry@CentOS src]$ git push origin wchar_support
上述命令將產生以下結果
Counting objects: 7, done. Compressing objects: 100% (4/4), done. Writing objects: 100% (4/4), 516 bytes, done. Total 4 (delta 1), reused 0 (delta 0) To gituser@git.server.com:project.git 3789fe8..9d201a9 wchar_support -> wchar_support
Tom 想看看 Jerry 在他的私有分支上做了什么,所以他試圖從wchar_support分支中提取最新的更改,但 Git 中止了操作并顯示以下錯誤消息。
[tom@CentOS src]$ git pull origin wchar_support
上面的命令產生以下結果
remote: Counting objects: 11, done. 63Git Tutorials remote: Compressing objects: 100% (8/8), done. remote: Total 8 (delta 2), reused 0 (delta 0) Unpacking objects: 100% (8/8), done. From git.server.com:project * branch wchar_support -> FETCH_HEAD Auto-merging src/string_operations.c CONFLICT (content): Merge conflict in src/string_operations.c Automatic merge failed; fix conflicts and then commit the result.
從錯誤信息可以看出,src/string_operations.c 中存在沖突。他運行 git diff 命令以查看更多詳細信息。
[tom@CentOS src]$ git diff
上面的命令產生以下結果
diff --cc src/string_operations.c index 52bec84,163a779..0000000--- a/src/string_operations.c +++ b/src/string_operations.c @@@ -1,8 -1,17 +1,22 @@@#include <stdio.h>#include <wchar.h>++<<<<<<< HEAD +/* wide character strlen fucntion */+size_t my_wc_strlen(const wchar_t *s) ++======= + wchar_t *my_wstrchr(wchar_t *ws, wchar_t wc) + { + + while (*ws) { if (*ws == wc) + return ws; + ++ws; + } + return NULL; + } + + size_t my_wstrlen(const wchar_t *s) ++>>>>>>>9d201a9c61bc4713f4095175f8954b642dae8f86 { const wchar_t *p = s;
由于 Tom 和 Jerry 更改了同一個函數的名稱,Git 處于混亂狀態,它要求用戶手動解決沖突。
Tom 決定保留 Jerry 建議的函數名稱,但保留他添加的注釋,原樣。刪除沖突標記后, git diff 將如下所示。
[tom@CentOS src]$ git diff
上述命令產生以下結果。
diff --cc src/string_operations.c diff --cc src/string_operations.c index 52bec84,163a779..0000000--- a/src/string_operations.c +++ b/src/string_operations.c @@@ -1,8 -1,17 +1,18 @@@#include <stdio.h>#include <wchar.h>+ wchar_t *my_wstrchr(wchar_t *ws, wchar_t wc) + { + while (*ws) { + if (*ws == wc) + return ws; + ++ws; + } + return NULL; + } + +/* wide character strlen fucntion */- size_t my_wc_strlen(const wchar_t *s) + size_t my_wstrlen(const wchar_t *s) { const wchar_t *p = s;
由于 Tom 修改了文件,他必須先提交這些更改,然后才能提取更改。
[tom@CentOS src]$ git commit -a -m 'Resolved conflict'[master 6b1ac36] Resolved conflict [tom@CentOS src]$ git pull origin wchar_support.
Tom 已經解決了沖突,現在 pull 操作將成功。
以上就是“Git沖突如何處理”這篇文章的所有內容,感謝各位的閱讀!相信大家閱讀完這篇文章都有很大的收獲,小編每天都會為大家更新不同的知識,如果還想學習更多的知識,請關注億速云行業資訊頻道。
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。