如何在git中直接合并两个以上的远程分支?
我试图寻找这个问题,但没有人回答我的问题 请让我举个例子:如何在git中直接合并两个以上的远程分支?,git,merge,remote-branch,Git,Merge,Remote Branch,我试图寻找这个问题,但没有人回答我的问题 请让我举个例子: 我在git服务器上有两个分支 origin/master origin/feature 分支“功能”是从“主”分支出来的,因为其他人都在“主”上工作,我不想影响他们,所以我在本地分支“功能”,并将其推到远程 由于“master”上有提交,两天后,我想在我的“feature”上提取最少的代码,是否有一种方法可以将代码从“origin/master”合并到“origin/feature”,然后只提取最少的“origin/feature”
我在git服务器上有两个分支
origin/master
origin/feature
分支“功能”是从“主”分支出来的,因为其他人都在“主”上工作,我不想影响他们,所以我在本地分支“功能”,并将其推到远程
由于“master”上有提交,两天后,我想在我的“feature”上提取最少的代码,是否有一种方法可以将代码从“origin/master”合并到“origin/feature”,然后只提取最少的“origin/feature”
我试过了
git checkout origin/feature
git merge origin/master
git status # you would see that this is the lease code with lots of commits
git checkout feature
git pull
但是,在我git pull
之后,我什么也没有得到,甚至那些最小的提交也丢失了
所以我意识到本地的origin/feature
只是远程的origin/feature
的图像。这就是我的方法不起作用的原因
另一种满足我要求的方法是
git checkout feature
git stash
git pull origin master:feature
git push origin feature:feature # or just [git push]
git stash pop stash@{0}
这就是我现在使用的方式
我想知道有没有一种方法可以直接合并这两个远程分支而无需推送任何东西?非常感谢您的回答。实际上,我们使用相同的方法,尽管命令并不完全相同。但是这样,我们仍然需要在本地合并分支,然后将分支推送到远程。我们可以在远程服务器中合并它们吗?不,通常不能通过git本身在服务器上合并。您可以在某些git服务(如github、atlassian stash等)上执行拉请求(或合并请求),这些服务最终可以合并,只要没有冲突,但在您的工作流中,您最好在本地服务器上合并。
#fetch latest changes in origin
git fetch origin
git checkout feature
#to sync feature with what you have now
git push origin feature
#merge locally, while you sit on feature
git merge origin/master
#now push the merge to the origin
git push origin feature