git merge 不合并

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/7746325/
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-10 12:03:46  来源:igfitidea点击:

git merge does not merge

gitgithub

提问by LAW

I have a master and "PersonalSite" branch for a codebase I'm working on. I have been repeatedly trying to merge the master into the PersonalSite branch to no avail.

我有一个用于我正在处理的代码库的 master 和“PersonalSite”分支。我一直在尝试将 master 合并到 PersonalSite 分支中,但无济于事。

This time, I thought I had everything straightened out, so I did:

这一次,我以为我已经理顺了一切,所以我做了:

git checkout master
git pull
git checkout PersonalSite
git pull
git merge master

It looked like everything was working, and it listed the set of files I would have expected, but there was a conflict. The conflict was correct and was as expected, so I fixed it, did "git add", "git commit", then "git push". But now, when I look at my git log, it just shows a commit with no code changes but a single conflict.

看起来一切正常,它列出了我期望的文件集,但存在冲突。冲突是正确的,正如预期的那样,所以我修复了它,做了“git add”,“git commit”,然后是“git push”。但是现在,当我查看我的 git 日志时,它只显示了一个没有代码更改但只有一个冲突的提交。

Now, when I run "git merge master" from the "PersonalSite" branch it says "Already up-to-date." but this clearly is not the case, as none of the changes I tried to merge actually merged. What exactly do I do to get master to actually merge at this point?

现在,当我从“PersonalSite”分支运行“git merge master”时,它显示“已经是最新的”。但这显然不是这种情况,因为我尝试合并的所有更改实际上都没有合并。在这一点上,我究竟该怎么做才能让 master 真正合并?

采纳答案by sciritai

By fixing the conflict and committing the merge conflict you've already completed the merge. Git adds merge commits when necessary, it's normal but they don't record anything except that the merge took place and what files were merged if there was a conflict. If you look more closely at your log you'll see there are in fact commits from master.

通过修复冲突并提交合并冲突,您已经完成了合并。Git 在必要时添加合并提交,这是正常的,但除了发生合并以及如果发生冲突时合并了哪些文件之外,它们不会记录任何内容。如果您更仔细地查看日志,您会发现实际上有来自 master 的提交。

EDIT: Okay, try this a test. You don't have to use the merge command, you can just pull master into PersonalSite.

编辑:好的,试试这个测试。您不必使用合并命令,只需将 master 拉入 PersonalSite 即可。

git checkout PersonalSite
git pull origin master

See what gives you. If it says up to date then you have merged correctly.

看看给你什么。如果它说是最新的,那么你已经正确合并了。

If you merge stuff locally like you did, then you need to ensure the local tracking branches are up to date. Always specify the branch name to pull from,

如果你像你一样在本地合并东西,那么你需要确保本地跟踪分支是最新的。始终指定要从中提取的分支名称,

git pull origin master
git pull origin PersonalSite

回答by Carrie

I realize that this is an older question now, but I was just having what I believe is the same problem. I couldn't get it resolved with any combination of the commands in other answers, but I did resolve it by running in the branch that I want merges into:

我意识到这是一个较旧的问题,但我只是遇到了我认为是同样的问题。我无法通过其他答案中的任何命令组合解决它,但我确实通过在要合并到的分支中运行来解决它:

git checkout <desired_branch_name> -- .

So for you:

所以对你来说:

git checkout master -- .

I found this answer here: git: checkout files from another branch into current branch (don't switch HEAD to the other branch)

我在这里找到了这个答案: git: checkout files from another branch into current branch(不要将 HEAD 切换到另一个分支)

回答by Cascabel

Assuming you have actually merged what you meant to merge (which is possible but hard to tell, given your explanation), you still won't see diffs in the output of git log, just the commit messages. Even if you use -pto tell git logto show diffs, the diff for the merge commit will generally be empty, or possibly show conflict resolutions. This is because semantically, only conflict resolutions are part of the merge commit; the other changes are part of other commits.

假设您实际上已经合并了您想要合并的内容(根据您的解释,这可能但很难说),您仍然不会在 的输出中看到差异git log,只会看到提交消息。即使你习惯-p告诉git log显示差异,合并提交的差异通常是空的,或者可能显示冲突解决方案。这是因为在语义上,只有冲突解决是合并提交的一部分;其他更改是其他提交的一部分。

If you want git logto show you the full effect of merge commits anyway, you can use:

如果你想git log向你展示合并提交的全部效果,你可以使用:

git log -p -m -c

The function of the options:

选项的作用:

  • -pdirects it to show diffs, not just commit messages;
  • -mtells it to show diffs for merge commits too; and
  • -ctells it to combine the two diffs into one for merge commits
  • -p指示它显示差异,而不仅仅是提交消息;
  • -m告诉它也显示合并提交的差异;和
  • -c告诉它将两个差异合并为一个以进行合并提交

The diff view in gitkwill do the same thing.

中的 diff 视图gitk会做同样的事情。

回答by Adam Dymitruk

a merge will not show any changes except your conflict resolutions.

除了您的冲突解决方案之外,合并不会显示任何更改。

To see the differences on either side of the merge do:

要查看合并两侧的差异,请执行以下操作:

git diff head^..

and

git diff head^2..

for the other side.

对于另一边。

Hope this helps.

希望这可以帮助。