因为存在未合并的文件,无法进行git pull操作。

5

我对git还非常陌生,正在努力弄清楚所有的工作原理。这是我的情况:我一直在笔记本电脑上开发Java项目。将其推送到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>'

请帮忙纠正这个问题。谢谢。

$ git status
on branch master
Your branch is ahead of 'origin/master' by 1 commit.
  (use "git push" to publish your local commits)

You have unmerged paths.
  (fix conflicts and run "git commit")

您是使用命令行还是 GUI 工具?如果是命令行,请发布 git status 的输出。 - Code-Apprentice
那么你不关心在尝试合并时所做的任何本地更改吗?你愿意用远程的内容覆盖你的本地内容吗? - Simon Whitehead
@Simon 是的。我只想使用远程分支上的所有内容来更新(覆盖)本地分支的所有内容。 - JOH
你在git status命令的输出中故意省略了具有冲突的文件列表吗?还是没有列出来? - Code-Apprentice
1个回答

9
您有两个选择:完成当前的合并或中止它。
  1. To finish the merge, you first need to check what files are being merged. You can do this with

    git status
    

    Now edit the files to resolve all merge conflicts. When you are satisfied that you have restored your code to a working state, you should run

    git add .
    git commit
    
  2. On the other hand, if you want to abort the current merge and remove all local changes, you can do

    git reset --hard HEAD
    

    WARNING Be very careful with this command. It will delete all of your local changes and you will not be able to restore them.

最后,当你完成了以上任意一项操作,你可以继续执行pull命令。

你如何编辑文件以解决所有合并冲突?几乎所有的文件都给我合并冲突。 - JOH
1
@JinOh 与编写代码时编辑文件的方式相同。您可以使用像NotePad这样简单的文本编辑器,像Notepad ++或Sublime Text这样更强大的编辑器,或者像Eclipse或IntelliJ这样完整的IDE。后者可能更可取,因为它们还具有帮助合并的工具。 - Code-Apprentice
也许我表达不够清楚。我并不是在问如何直接编辑文件。我想知道需要编辑哪些内容才能进行合并?或者,我只想用存储库中的文件替换所有本地文件。git reset --hard HEAD 对我没用。 - JOH
@JinOh 文件中清楚地标记了合并冲突。(提示:寻找意外的编译器错误。) 如果需要更多帮助,请描述一下“没有起作用”是什么意思。 - Code-Apprentice

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接