简体   繁体   English

Git 从第三个分支合并

[英]Git merge from a third branch

I have two branches, homolog and development .我有两个分支, homologdevelopment

development is ahead of homolog , but I want to make development a mirror of homolog . development领先于homolog ,但我想让development成为homolog的镜像。

If I could commit straight into development, I would say:如果我可以直接投入开发,我会说:

On branch development
Your branch is up to date with 'origin/development'.
$ git pull origin homolog
$ git add *
$ git commit -m "merges homolog into development"

But in my particular case, I am not allowed to commit straight into development , so I cannot perform the instructions above.但在我的特殊情况下,不允许我直接投入development ,因此我无法执行上述说明。

Instead, I have to create a branch from development , pull the code from homolog, and then push it ( via pull request) to development.相反,我必须从development创建一个分支,从 homolog 中提取代码,然后将它(通过pull request)推送到 development。

What I've tried:我试过的:

On branch development
Your branch is up to date with 'origin/development'.
$ git checkout -b my-cool-branch
Switched to a new branch 'my-cool-branch'
$ git pull origin homolog

My intention was to get the code from homolog at this point.此时我的意图是从 homolog 获取代码。 But unfortunately, git says:但不幸的是,git 说:

Already up to date!
Merge made by the 'recursive' strategy.

What does not make sense at all (because I'm a noob).根本没有意义(因为我是菜鸟)。

I want to make development identical to homolog我想让发展与同系物相同

First of all, this is wrong:首先,这是错误的:

On branch development
Your branch is up to date with 'origin/development'.
$ git pull origin homolog
$ git add *
$ git commit -m "merges homolog into development"

The commit at the end does not merge homolog into development.最后的commit不会将同系物合并到开发中。 What merges homolog into development is the pull at the start! homolog 融入 development 的是一开始的pull A pull , by default, is a merge .默认情况下, pullmerge The other stuff just appends any uncommitted material — but you probably would not have been allowed to do the pull if there were any uncommitted material, so it's pretty much pointless.其他内容只是附加任何未提交的材料 — 但如果有任何未提交的材料,您可能不会被允许进行pull ,因此这几乎毫无意义。

Okay, with that out of the way: what you are hoping git pull origin homolog will do is merge homolog into development as a fast forward .好吧,让开这个:你希望git pull origin homolog会做的是将 homolog 合并到 development作为快进 That is indeed what will happen if homolog diverged from development and is purely ahead of development (ie not also behind development at all).如果同系物从发育中分离出来并且完全领先于发育(即根本不落后于发育),那确实会发生这种情况。

But then we come to your statement here:但随后我们在这里发表您的声明:

I have to create a branch from development, pull the code from homolog, and then push it (via pull request) to development.我必须从开发中创建一个分支,从 homolog 中提取代码,然后将其(通过拉取请求)推送到开发中。

Okay, well, if that rule is truly the case, then what you want to do is impossible .好吧,如果那条规则真的是这样的话,那么你想做的事情是不可能的。 The reason is that a pull request is nothing but a protracted merge at the server side.原因是拉取请求不过是在服务器端进行的旷日持久的合并。 But no form of pull request will permit you to do a fast-forward merge at the server side.但是任何形式的拉取请求都不允许您在服务器端进行快进合并。 The closest you can get is a "rebase and merge":您可以获得的最接近的是“rebase and merge”:

https://docs.github.com/en/github/collaborating-with-issues-and-pull-requests/about-pull-request-merges#rebase-and-merge-your-pull-request-commits https://docs.github.com/en/github/collaborating-with-issues-and-pull-requests/about-pull-request-merges#rebase-and-merge-your-pull-request-commits

That cherry picks the commits from homolog onto development.那颗樱桃从同系物中挑选提交到开发中。 But they are not the same commits;但它们不是相同的提交; they are copies.他们是副本。 So development and homolog will not be "identical".所以发展和同系物不会“相同”。 Still, they should result in the very same appearance: that is, after such a pull request merge, checking out development and checking out homolog would give the same outcome in the working tree, which seems to be the bulk of what you are after.不过,它们应该产生完全相同的外观:也就是说,在这样的拉取请求合并之后,检查开发和检查同系物会在工作树中产生相同的结果,这似乎是你所追求的大部分。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM