1

我在我的 master 分支上,这是一个完美的干净(但 git 显示它比 origin/master 领先 14 次提交)。当我尝试从原点(Eagle)拉出不同的分支时,git 想让我合并一些文件。

这不是我所期望的:当拉一个分支时,它应该导入远程分支并保持当前 HEAD 不变,并且不会因合并冲突而困扰我。在我看来,这两个分支分开生活,但彼此和平相处,没有任何冲突。但这种看法不再成立。

是什么导致这些冲突以及如何在不合并的情况下恢复 2 个不同的分支?

下面是命令行上 git 会话的记录。

HEAD is now at 34e47ab ISS-652 misspelled MockBean in test/ApplicationContext
build@jenkins/p-project/workspace> git status
# On branch master
# Your branch is ahead of 'origin/master' by 14 commits.
#
nothing to commit (working directory clean)
build@jenkins/p-project/workspace> git log -5
.. Same as origin
build@jenkins/p-project/workspace> git push origin master
Everything up-to-date
build@jenkins/p-project/workspace> git status
# On branch master
# Your branch is ahead of 'origin/master' by 14 commits.
#
nothing to commit (working directory clean)
build@jenkins/p-project/workspace> git pull origin Eagle
From ssh://git@stash.europe.intranet:7999/hig/p-project-container
 * branch            Eagle     -> FETCH_HEAD
Auto-merged pom.xml
CONFLICT (content): Merge conflict in pom.xml
Auto-merged p-project-client/pom.xml
CONFLICT (content): Merge conflict in p-project-client/pom.xml
Auto-merged p-project-container-conf/pom.xml
CONFLICT (content): Merge conflict in p-project-container-conf/pom.xml
Auto-merged p-project-container-conf/src/main/resources/dpl/P-Project_Container.xml
CONFLICT (content): Merge conflict in p-project-container-conf/src/main/resources/dpl/P-Project_Container.xml
Auto-merged p-project-container-conf/src/main/resources/was/P-Project_Container-app-env.cfg
Auto-merged p-project-container-ear/pom.xml
CONFLICT (content): Merge conflict in p-project-container-ear/pom.xml
Auto-merged p-project-container-filters/pom.xml
CONFLICT (content): Merge conflict in p-project-container-filters/pom.xml
Auto-merged p-project-container-ldap/pom.xml
CONFLICT (content): Merge conflict in p-project-container-ldap/pom.xml
Auto-merged p-project-container-tomcattest/pom.xml
CONFLICT (content): Merge conflict in p-project-container-tomcattest/pom.xml
Auto-merged p-project-container-web/pom.xml
CONFLICT (content): Merge conflict in p-project-container-web/pom.xml
Automatic merge failed; fix conflicts and then commit the result.
build@jenkins/p-project/workspace>
4

2 回答 2

1

我将解释您所做的事情,然后很明显您得到的结果是可以预期的。

master自上次与远程存储库同步以来,您对分支进行了 14 次提交:

git commit -m 'You did something'   # you did this 14 times

接下来,您将工作推送到远程:

git push origin master

请注意,git status您的本地分支仍然显示为 14 次提交master。您的本地分支在旧的本地跟踪分支之前,但与远程完全同步master

接下来,您执行了以下操作:

git pull origin Eagle

这是以下的简写:

git fetch origin
git merge origin/Eagle

换句话说,您首先从远程获取最新更改到所有跟踪分支(好),然后将Eagle分支合并到本地master(坏)。发生这种情况的原因是因为您在执行此操作之前从未切换过分支git pull

你需要做什么来解决这个问题:

您需要采取 2 个步骤。首先,您需要撤消不正确的合并到master分支中。其次,您应该将分支切换到Eagle,然后执行git pull.

# on the master branch
git log
# find the SHA-1 hash immediately BEFORE the bad merge, then do
git reset --hard SHA-1
# next switch to the Eagle branch
git checkout Eagle
# finally do the correct pull
git pull origin Eagle

您可能仍然有合并冲突,但它们将是真正的冲突,而不是合并Eaglemaster.

于 2015-11-24T09:08:23.897 回答
0

它的作用是git pull origin branch获取远程分支并将其合并到您当前的本地分支中。因此,上述命令的结果是 - 将远程分支合并eagle到本地 master。

我猜你想要的是创建一个新的本地独立分支来跟踪相应的远程分支。你可以这样做

git fetch
git checkout -b eagle --track origin/eagle

这将创建一个新的单独的本地分支eagle,该分支将反映远程分支eagle

这个本地分支将独立于您的本地 master 分支,并保持您的本地 master 不变。

你可以做git status,它会显示Your branch is up-to-date with 'origin/eagle'.,你可以用 checkout mastergit checkout master然后做一个git statuswill show ahead by 14 commits

于 2015-11-24T09:08:51.310 回答