您的位置:首页 > 其它

Git 冲突处理

2016-01-22 00:51 148 查看


对付冲突

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 建议的函数名,但他使用原来注释,因为这是他加入的。删除冲突标记混帐后差异会看起来像这样。
[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 已经解决冲突,现在推送操作将成功。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: