当前正在发生的事情是,您有一组特定的文件,您先前尝试过合并,但是它们引发了合并冲突。理想情况下,如果遇到合并冲突,他应该手动解决它们,并使用提交更改git add file.name && git commit -m "removed merge conflicts"
。现在,另一个用户已更新其存储库中有问题的文件,并将其更改推送到公共上游存储库中。
碰巧的是,您的合并与(可能是)上次提交的冲突没有得到解决,因此您的文件没有被正确合并,因此文件的U
(unmerged
)标志。因此,现在,当您执行时git pull
,git会引发错误,因为您拥有该文件的某些版本,但无法正确解决。
要解决此问题,您必须先解决有问题的合并冲突,然后添加并提交更改,然后才能执行git pull
。
样本复制和问题解决:
# Note: commands below in format `CUURENT_WORKING_DIRECTORY $ command params`
Desktop $ cd test
首先,让我们创建存储库结构
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中,如果执行a git pull
,它将引发冲突
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.
如果我们忽略克隆中的冲突,而现在在原始存储库中进行更多提交,
repo_clone $ cd ../repo
repo $ echo "text1" >> file && git add file && git commit -m "msg" && cd ../repo_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'.
请注意,file
现在处于未合并状态,如果执行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
因此,要解决此问题,我们首先需要解决我们之前忽略的合并冲突
repo_clone $ vi file
并将其内容设置为
text2
text1
text1
然后添加它并提交更改
repo_clone $ git add file && git commit -m "resolved merge conflicts"
[master 39c3ba1] resolved merge conflicts