另一个远程的 Git 合并分支

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/12921125/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-19 07:39:11  来源:igfitidea点击:

Git merge branch of another remote

linuxgitcommand-line

提问by Brian Campbell

Nowadays, I see a lot of commits from Linus Torvalds and/or Gitster that look like so:

现在,我看到 Linus Torvalds 和/或 Gitster 的很多提交看起来像这样:

Merge branch 'maint' of git://github.com/git-l10n/git-po into maint …
* 'maint' of git://github.com/git-l10n/git-po:
  l10n: de.po: fix a few minor typos

or:

或者:

Merge branch 'upstream' of git://git.linux-mips.org/pub/scm/ralf/upst… …
…ream-linus

Pull MIPS update from Ralf Baechle:
...
* 'upstream' of git://git.linux-mips.org/pub/scm/ralf/upstream-linus: (22 commits)
  MIPS: SNI: Switch RM400 serial to SCCNXP driver
...

I have no idea how would one do that, although, I know about the git remoteand git checkoutand git mergethat I use to merge forks (or "pull requests") but it does not generate such message, why? and how would someone do that (provide examples please)?

我不知道如何做到这一点,虽然,我知道用于合并分叉(或“拉取请求”)的git remotegit checkoutgit merge但它不会生成这样的消息,为什么?有人会怎么做(请提供示例)?

P.S: I'm a fan of Linus Torvalds commits etc, like how detailed the description of his merges look ;P

PS:我是 Linus Torvalds 提交等的粉丝,比如他的合并描述的详细程度;P

P.S: This is how I used to merge stuff:

PS:这就是我用来合并东西的方式:

git remote add anotherremoot
git checkout -b anotherbranch
git pull remoteshortcut
...do tests...
git checkout master
git merge anotherbranch
git push

The above example I learned from: http://viget.com/extend/i-have-a-pull-request-on-github-now-what

上面的例子我从:http: //viget.com/extend/i-have-a-pull-request-on-github-now-what

回答by Brian Campbell

Just use git pullto pull the remote branch into master:

只需用于git pull将远程分支拉入master

git remote add something git://host.example.com/path/to/repo.git
git checkout master
git pull something master

Or do it without adding a remote:

或者在不添加遥控器的情况下进行:

git pull git://host.example.com/path/to/repo.git

git pullfetches the remote branch, and merges it into the local branch. If possible, it does a fast-forward merge, which just means that it updates the current master to the latest commit without generating a merge commit. But if there are changes on both sides, it will do a merge, like the ones you see Linus and Junio doing, with the remote URL included.

git pull获取远程分支,并将其合并到本地分支。如果可能,它会进行快进合并,这仅意味着它将当前 master 更新为最新提交,而不会生成合并提交。但是如果双方都有变化,它会进行合并,就像你看到 Linus 和 Junio 所做的那样,包括远程 URL。

If you want to guarantee that you get a merge commit, even if it could fast forward, do git pull -no-ff. If you want to make sure that pullnever creates a merge commit (so fails if there are changes on both sides), do git pull --ff-only.

如果你想保证你得到一个合并提交,即使它可以快进,做git pull -no-ff. 如果您想确保pull永远不会创建合并提交(如果双方都有更改则失败),请执行git pull --ff-only.

If you want to include a more detailed message, like the full log that Linus provides, do git pull --log. If you want to edit the message, instead of just using the automatically created message, use git pull --edit. See documentation for git pullfor more options.

如果您想包含更详细的消息,例如 Linus 提供的完整日志,请执行git pull --log. 如果要编辑消息,而不是仅使用自动创建的消息,请使用git pull --edit。有关更多选项,请参阅文档git pull