git merge 不合并
我有一个 master 和“PersonalSite”分支用于我正在处理的代码库。我曾多次尝试将master合并到PersonalSite分支中,但无济于事。
这一次,我以为我已经把一切都搞清楚了,所以我做到了:
git checkout master
git pull
git checkout PersonalSite
git pull
git merge master
看起来一切正常,并且列出了我期望的文件集,但存在冲突。冲突是正确的并且符合预期,所以我修复了它,执行“git add”,“git commit”,然后“git push”。但现在,当我查看 git 日志时,它只显示一次提交,没有代码更改,只有一个冲突。
现在,当我从“PersonalSite”分支运行“git merge master”时,它显示“已经是最新的”。但情况显然并非如此,因为我尝试合并的所有更改都没有真正合并。此时我到底该怎么做才能让 master 真正合并?
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.
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.
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
通过修复冲突并提交合并冲突,您已经完成了合并。 Git 在必要时添加合并提交,这是正常的,但除了合并发生以及发生冲突时合并了哪些文件之外,它们不会记录任何内容。如果您更仔细地查看日志,您会发现实际上有来自 master 的提交。
编辑:
好吧,尝试一下这个测试。您不必使用合并命令,只需将 master 拉入 PersonalSite 即可。
看看能给你带来什么。如果它说是最新的,那么你已经正确合并了。
如果您像以前一样在本地合并内容,那么您需要确保本地跟踪分支是最新的。始终指定要从中提取的分支名称,
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.
EDIT:
Okay, try this a test. You don't have to use the merge command, you can just pull master into PersonalSite.
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:从另一个签出文件分支到当前分支(不要将 HEAD 切换到另一个分支)
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:
So for you:
I found this answer here:
git: checkout files from another branch into current branch (don't switch HEAD to the other branch)
假设您实际上已经合并了要合并的内容(这是可能的,但根据您的解释很难判断),您仍然不会在 git log 的输出中看到差异,而只会看到提交消息。即使您使用 -p 告诉 git log 显示差异,合并提交的差异通常为空,或者可能显示冲突解决方案。这是因为从语义上讲,只有冲突解决才是合并提交的一部分;其他更改是其他提交的一部分。
如果您希望 git log 无论如何都显示合并提交的完整效果,您可以使用:
选项的功能:
-p
指示它显示差异,而不仅仅是显示差异提交消息;-m
告诉它也显示合并提交的差异;gitk
中的 diff 视图也会做同样的事情。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-p
to tellgit log
to 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.If you want
git log
to show you the full effect of merge commits anyway, you can use:The function of the options:
-p
directs it to show diffs, not just commit messages;-m
tells it to show diffs for merge commits too; and-c
tells it to combine the two diffs into one for merge commitsThe diff view in
gitk
will do the same thing.除了冲突解决方案之外,合并不会显示任何更改。
要查看合并两侧的差异,请执行以下操作:
和
对于另一侧。
希望这有帮助。
a merge will not show any changes except your conflict resolutions.
To see the differences on either side of the merge do:
and
for the other side.
Hope this helps.