gpt4 book ai didi

git - 为什么 git 说 "Pull is not possible because you have unmerged files"?

转载 作者:IT王子 更新时间:2023-10-29 01:18:09 28 4
gpt4 key购买 nike

当我尝试在终端中 pull 入我的项目目录时,我看到以下错误:

harsukh@harsukh-desktop:~/Sites/branch1$ git pull origin master
U app/config/app.php
U app/config/database.php
U app/routes.php
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 说 “Pull is not possible because you have unmerged files”,我该如何解决?

最佳答案

当前发生的情况是,您有一组特定的文件,您之前曾尝试 merge 这些文件,但它们引发了 merge 冲突。理想情况下,如果遇到 merge 冲突,他们应该手动解决它们,并使用 git add file.name && git commit -m "removed merge conflicts" 提交更改。现在,另一个用户更新了他们存储库中的相关文件,并将他们的更改推送到公共(public)上游存储库。

碰巧,你的 merge 冲突(可能)最后一次提交没有解决,所以你的文件没有正确 merge ,因此 U(unmerged) 文件的标志。所以现在,当你执行 git pull 时,git 会抛出错误,因为你有某个版本的文件,它没有被正确解析。

要解决此问题,您必须先解决有问题的 merge 冲突,然后添加并提交更改,然后才能执行 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 中,如果你执行 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'.

请注意,文件 现在处于未 merge 状态,如果我们执行 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

因此,要解决这个问题,我们首先需要解决我们之前忽略的 merge 冲突

repo_clone $ vi file

并将其内容设置为

text2
text1
text1

然后添加它并提交更改

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

关于git - 为什么 git 说 "Pull is not possible because you have unmerged files"?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26376832/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com