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

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说“拉是不可能的,因为你有未合并的文件”,我该如何解决它?


当前回答

只需执行以下命令:

git reset --hard

其他回答

您在本地有一些文件需要合并,然后才能进行提取。您可以签出这些文件,然后拖动以覆盖本地文件。

git checkout app/config/app.php app/config/database.php app/routes.php
git pull origin master

我也有同样的问题 在我的案例中,步骤如下-

删除了所有以U(未合并)符号开始的文件。作为- - - - - -


U   project/app/pages/file1/file.ts
U   project/www/assets/file1/file-name.html

从master中提取代码


$ git pull origin master

检查状态


 $ git status

这是它出现的消息 分别有2个和1个不同的提交。 (使用“git pull”将远程分支合并到您的分支中) 你有未合并的路径。 (修复冲突并运行“git commit”)

Unmerged路径: (使用“git add…”来标记分辨率)

both modified:   project/app/pages/file1/file.ts
both modified:   project/www/assets/file1/file-name.html

增加了所有新的变化-


    $ git add project/app/pages/file1/file.ts
project/www/assets/file1/file-name.html

在head上提交更改


$ git commit -am "resolved conflict of the app."

〇推送密码


$ git push origin master

用这个图像可以解决哪一个问题

以下步骤:

step-1 : git reset --hard HEAD  (if you want to reset it to head)
step-2 : git checkout Master 
step-3 : git branch -D <branch Name>
(Remote Branch name where you want to get pull) 
step-4 : git checkout <branch name>
step-5 : git pull. (now you will not get any
error)

谢谢, Sarbasish

如果你想下拉一个远程分支到本地运行(比如为了检查或测试),当你$ git下拉时,你会得到本地合并冲突:

$ git checkout REMOTE-BRANCH
$ git pull  (you get local merge conflicts)
$ git reset --hard HEAD (discards local conflicts, and resets to remote branch HEAD)
$ git pull (now get remote branch updates without local conflicts)

如果你不想合并这些变化,并且仍然想要更新你的本地,那么运行:

git reset --hard HEAD  

这将重置您的本地与HEAD,然后拉动您的远程使用git拉。

如果你已经在本地提交了你的合并(但还没有推送到远程),并且想要还原它:

git reset --hard HEAD~1