git pull origin branch想要在clean current master分支上合并

时间:2015-11-24 08:52:50

标签: git git-branch git-merge-conflict

我正在使用我的主分支,这是一个完美的干净(但git表示它在14个提交之前已经超过origin / master)。当我尝试从源(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>

2 个答案:

答案 0 :(得分:1)

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

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

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

接下来,您将工作推送到遥控器:

git push origin master

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

接下来,你做了这个:

git pull origin Eagle

这是:

的简写
git fetch origin
git merge origin/Eagle

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

您需要采取哪些措施来解决此问题:

你需要采取两个步骤。首先,您需要撤消不正确的合并到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

您可能仍然存在合并冲突,但它们将是真正的冲突,而不是将Eagle合并到master中的结果。

答案 1 :(得分:1)

git pull origin branch的作用是将远程分支提取并合并到当前的本地分支中。因此,上述命令的结果是 - 将远程分支eagle合并到本地主服务器中。

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

做到这一点
git fetch
git checkout -b eagle --track origin/eagle

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

此本地分支将独立于您当地的主分支机构,并保持您的本地主分支不受影响。

您可以执行git status,它会显示Your branch is up-to-date with 'origin/eagle'.,您可以使用git checkout master结帐主人,然后git status会显示ahead by 14 commits