Git-handling-conflicts

提供:Dev Guides
移動先:案内検索

Git-競合の処理

wchar_supportブランチで変更を実行する

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 name
1 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 [email protected]:project.git
64192f9..3789fe8 wchar_support -> wchar_support

Master Branchで変更を実行する

一方、マスターブランチでは、トムは同じ関数の名前も変更し、変更をマスターブランチにプッシュします。

[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_strlen
1 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 [email protected]: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 string
1 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 [email protected]:project.git
3789fe8..9d201a9 wchar_support -> wchar_support

タックルの競合

トムは自分のプライベートブランチでジェリーが何をしているかを見たいので、 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;

トムとジェリーの両方が同じ関数の名前を変更したため、Gitは混乱の状態にあり、ユーザーに競合を手動で解決するように求めています。

トムはジェリーが提案した関数名を保持することにしましたが、彼はコメントをそのまま追加しました。 競合マーカーを削除すると、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@CentOS src]$ git commit -a -m 'Resolved conflict'
[master 6b1ac36] Resolved conflict

[tom@CentOS src]$ git pull origin wchar_support.

トムは競合を解決し、プル操作が成功するようになりました。