缪妍缪宇

没有伞的孩子只能拼命往前奔跑!

git冲突解决

您是否有遇到类似下面的的git冲突提示、有的话、让我们一起来看看是怎么产生这样的问题的!
Pull is not possible because you have unmerged files.
Please, fix them up in the work tree, and then use 'git add/rm <file>'

一、首先创建一个测试库、和测试clone库

test $ mkdir repo && cd repo && git init && touch file && git add file && git commit -m "msg"
repo $ cd .. && git clone repo repo_clone && cd repo_clone
repo_clone $ echo "text2" >> file && git add file && git commit -m "msg" && cd ../repo
repo $ echo "text1" >> file && git add file && git commit -m "msg" && cd ../repo_clone

二、现在在repo_clone执行git pull就会报conflicts

repo_clone $ git pull origin master
remote: Counting objects: 5, done.
remote: Total 3 (delta 0), reused 0 (delta 0)
Unpacking objects: 100% (3/3), done.
From /home/anshulgoyal/Desktop/test/test/repo
 * branch            master     -> FETCH_HEAD
   24d5b2e..1a1aa70  master     -> origin/master
Auto-merging file
CONFLICT (content): Merge conflict in file
Automatic merge failed; fix conflicts and then commit the result.

三、如果我们忽略这个冲突不去解决它、而远端origin还在执行commit

repo_clone $ cd ../repo
repo $ echo "text1" >> file && git add file && git commit -m "msg" && cd ../repo_clone

四、此时我们再来执行clone库里面的git pull、就会得到我们遇到的问题。

repo_clone $ git pull
U   file
Pull is not possible because you have unmerged files.
Please, fix them up in the work tree, and then use 'git add/rm <file>'
as appropriate to mark resolution, or use 'git commit -a'.

五、此时我们执行git status就可以清晰的看到未处理的冲突问题。

repo_clone $ git status
On branch master
Your branch and 'origin/master' have diverged,
and have 1 and 1 different commit 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:      file

六、所以要解决这个问题、我们就需要解决之前遇到的冲突而没有解决掉得问题。

vi file 把里面的冲突解决掉、让后重新提交file

repo_clone $ git add file && git commit -m "resolved merge conflicts"
[master 39c3ba1] resolved merge conflicts

问题解决。

posted @ 2015-04-16 11:33  缪妍缪宇  阅读(890)  评论(0编辑  收藏  举报