目前发生的情况是,您有一组特定的文件,您之前已经尝试合并这些文件,但它们引发了合并冲突。
理想情况下,如果有人遇到合并冲突,他们应该手动解决,并使用git add file.name && git commit -m "removed merge conflicts"提交修改。
现在,另一个用户已经在他们的存储库中更新了有问题的文件,并将其更改推到公共上游回购。
碰巧的是,上次提交的合并冲突(可能)没有解决,所以文件没有合并,因此文件有U(未合并)标志。
当你进行git pull时,git会抛出错误,因为你有某个版本的文件,没有被正确解析。
要解决这个问题,您必须解决合并冲突,并在进行git拉取之前添加并提交更改。
样本再现和解决问题:
# 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中,如果您执行git拉取,它将抛出冲突
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
然后我们再来一次,我们得到
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状态,我们可以清楚地看到相同的情况:
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