Git 合并是不可能的,因为我有未合并的文件

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/36086202/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-09 04:02:31  来源:igfitidea点击:

Git merge is not possible because I have unmerged files

gitmerge

提问by Kokodoko

git continues to confuse me with its unhelpful error warnings This one really deserves a prize:

git 继续以其无用的错误警告让我感到困惑 这一个确实值得奖励:

git merge is not possible because you have unmerged files

My situation: My master branch on github was edited (directly in the browser) while my local master branch was also edited.

我的情况:我在 github 上的 master 分支被编辑(直接在浏览器中),同时我的本地 master 分支也被编辑。

I wrongly suppose you could simply merge the two versions and be done with it, but also, I cannot merge - because my files are unmerged.

我错误地认为您可以简单地合并两个版本并完成它,但是,我无法合并 - 因为我的文件未合并。

git merge remote/master

results in

结果是

error: merge is not possible because you have unmerged files.
hint: Fix them up in the work tree, and then use 'git add/rm <file>'
hint: as appropriate to mark resolution and make a commit.
fatal: Exiting because of an unresolved conflict.

So, after adding and committing the local change and then trying to merge again, I get:

因此,在添加并提交本地更改然后再次尝试合并后,我得到:

merge: remote/master - not something we can merge

Clearly I am missing something essential here... Do I have the wrong idea about what merging means? How do I fix this issue of having a different remote master / local master branch?

显然我在这里遗漏了一些重要的东西......我对合并意味着什么有错误的想法吗?如何解决具有不同远程主/本地主分支的问题?

采纳答案by Jonathan.Brink

The error message:

错误信息:

merge: remote/master - not something we can merge

合并:远程/主 - 不是我们可以合并的东西

is saying that Git doesn't recognize remote/master. This is probably because you don't have a "remote" named "remote". You have a "remote" named "origin".

是说 Git 无法识别remote/master. 这可能是因为您没有名为“remote”的“remote”。您有一个名为“origin”的“远程”。

Think of "remotes" as an alias for the url to your Git server. masteris your locally checked-out version of the branch. origin/masteris the latest version of masterfrom your Git server that you have fetched (downloaded). A fetchis always safe because it will only update the "origin/x" version of your branches.

将“遥控器”视为 Git 服务器 url 的别名。master是您本地签出的分支版本。origin/mastermaster从您的 Git 服务器获取(下载)的最新版本。Afetch总是安全的,因为它只会更新分支的“origin/x”版本。

So, to get your masterbranch back in sync, first download the latest content from the git server:

所以,为了让你的master分支恢复同步,首先从 git 服务器下载最新的内容:

git fetch

Then, perform the merge:

然后,执行合并:

git merge origin/master

...But, perhaps the better approach would be:

...但是,也许更好的方法是:

git pull origin master

The pullcommand will do the fetchand mergefor you in one step.

pull命令将一步完成fetchmerge为您完成。

回答by Mosaku Abayomi

I repeatedly had the same challenge sometime ago. This problem occurs mostly when you are trying to pull from the remote repository and you have some files on your local instance conflicting with the remote version, if you are using git from an IDE such as IntelliJ, you will be prompted and allowed to make a choice if you want to retain your own changes or you prefer the changes in the remote version to overwrite yours'. If you don't make any choice then you fall into this conflict. all you need to do is run:

前一段时间我反复遇到过同样的挑战。此问题主要发生在您尝试从远程存储库中拉取时,并且您的本地实例上的某些文件与远程版本冲突时,如果您使用来自 IntelliJ 等 IDE 的 git,则会提示您并允许您创建选择是要保留自己的更改还是希望远程版本中的更改覆盖您的更改。如果你不做任何选择,那么你就会陷入这种冲突。你需要做的就是运行:

git merge --abort # The unresolved conflict will be cleared off

And you can continue what you were doing before the break.

你可以继续你在休息前所做的事情。

回答by davidjmcclelland

Another potential cause for this (Intellij was involved in my case, not sure that mattered though): trying to merge in changes from a main branch into a branch off of a feature branch.

另一个可能的原因(Intellij 参与了我的案例,但不确定这是否重要):尝试将更改从主分支合并到功能分支的分支。

In other words, merging "main" into "current" in the following arrangement:

换句话说,按照以下安排将“main”合并为“current”:

main
  |
  --feature
      |
      --current

I resolved all conflicts and GiT reported unmerged files and I was stuck until I merged from main into feature, then feature into current.

我解决了所有冲突,GiT 报告了未合并的文件,直到我从主合并到功能,然后将功能合并到当前为止。

回答by Tobias Neis

I ran into the same issue and couldn't decide between laughing or smashing my head on the table when I read this error...

我遇到了同样的问题,当我读到这个错误时,无法决定是笑还是把头砸在桌子上......

What git really tries to tell you: "You are already in a merge state and need to resolve the conflicts there first!"

git 真正想告诉你的是:“你已经处于合并状态,需要先解决那里的冲突!”

You tried a merge and a conflict occured. Then, git stays in the merge state and if you want to resolve the merge with other commands git thinks you want to execute a new merge and so it tells you you can't do this because of your current unmerged files...

您尝试了合并,但发生了冲突。然后,git 保持合并状态,如果您想用其他命令解决合并问题,git 认为您想执行新的合并,因此它告诉您由于当前未合并的文件而无法执行此操作...

You can leave this state with git merge --abortand now try to execute other commands.

你可以离开这个状态,git merge --abort现在尝试执行其他命令。

In my case I tried a pull and wanted to resolve the conflicts by hand when the error occured...

在我的情况下,我尝试了拉动,并希望在发生错误时手动解决冲突...