$ git checkout -b site Switched to a new branch 'site' $ vim test.txt $ head -1 test.txt b $ git commit -am 'changed the site' [change_site d7e7346] changed the site 1 file changed, 1 insertion(+), 1 deletion(-)
$ git checkout master Switched to branch 'master' $ head -1 test.txt b $ vim test.txt $ cat test.txt a 新增加一行 $ git diff diff --git a/test.txt b/test.txt index 704c4e7..f84e2a4 100654 --- a/test.txt +++ b/test.txt @@ -1 +1,2 @@ a +新增加一行 $ git commit -am '新增加一行' [master 14b43ca] 新增加一行 1 file changed, 1 insertion(+)
现在这些改变已经记录到我的 “master” 分支了。接下来我们将 “site” 分支合并过来。
1 2 3 4 5 6 7 8 9 10 11
$ git merge site Auto-merging test.txt CONFLICT (content): Merge conflict in test.txt Automatic merge failed; fix conflicts and then commit the result. $ cat test.txt <<<<<<< HEAD a 新增加一行 ======= b >>>>>>> change_site
我们将前一个分支合并到 “master” 分支,一个合并冲突就出现了,接下来我们需要手动去修改它。
1 2 3 4 5 6 7 8 9 10 11 12 13
$ vim test.txt $ cat test.txt b 新增加一行 $ git diff diff --cc test.txt index f85cea4,bccc562..0000000 --- a/test.txt +++ b/test.txt @@@ -1,2 -1,1 +1,2 @@@ - a + b +新增加一行
在 Git 中,我们可以用 git add 要告诉 Git 文件冲突已经解决
1 2 3 4 5 6 7
$ git status -s UU test.txt $ git add test.txt $ git status -s M test.txt $ git commit [master 88afee8] Merge branch 'site'