简体   繁体   中英

Git merge from a third branch

I have two branches, homolog and development .

development is ahead of homolog , but I want to make development a mirror of 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.

Instead, I have to create a branch from development , pull the code from homolog, and then push it ( via pull request) to 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. But unfortunately, git says:

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. What merges homolog into development is the pull at the start! A pull , by default, is a merge . 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.

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 . 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.

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":

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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