git 合并拉取请求
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/14391421/
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
Merging pull requests together
提问by George Wilson
Someone has submitted a set of pull requests to my repository on github. Unfortunately they've done this in several pull requests (one for each file) rather than submitting all the pull request for all the files in one go.
有人向我在 github 上的存储库提交了一组拉取请求。不幸的是,他们已经在多个拉取请求(每个文件一个)中完成了此操作,而不是一次性提交所有文件的所有拉取请求。
After requesting him to merge them as one - and not getting any response I'm now trying to merge these pull requests together myself in the Git Bash - but having little luck - I'm quite happy using the merge buttons and making commits through the GitHub program on windows but little more. I have no real understanding of the git shell - so if someone could go through the process of how I can merge these pull requests together (none of them conflict in anyway) it would be much appreciated.
在请求他将它们合并为一个之后 - 并且没有得到任何回应,我现在试图在 Git Bash 中自己将这些拉取请求合并在一起 - 但运气不佳 - 我很高兴使用合并按钮并通过Windows 上的 GitHub 程序,但仅此而已。我对 git shell 没有真正的了解 - 所以如果有人可以完成我如何将这些拉取请求合并在一起的过程(无论如何它们都没有冲突),我将不胜感激。
回答by shengy
Say if you have 3 pull requests A,B,C which are on three branches bA,bB,bC. and your main branch is master.
假设您有 3 个拉取请求 A、B、C,它们位于三个分支 bA、bB、bC。而你的主分支是 master。
First get all of his branches to your local repo without merging it.
git fetch his-repo
首先将他的所有分支放到你的本地仓库中,而不是合并它。
git fetch his-repo
so now your repo may have four branches: master, bA, bB, bC
所以现在你的 repo 可能有四个分支: master, bA, bB, bC
I will create a branch from master called f-merge-his-repo
我将创建一个名为 master 的分支 f-merge-his-repo
git checkout master
This makes sure that f-merge-his-repo branches out from master.
git checkout master
这确保 f-merge-his-repo 从 master 分支出来。
git checkout -b f-merge-his-repo
This creates the branch f-merge-his-repo and switch to it.
git checkout -b f-merge-his-repo
这将创建分支 f-merge-his-repo 并切换到它。
So now you are currently on f-merge-his-repo, use the following commands:
所以现在你目前在 f-merge-his-repo 上,使用以下命令:
git merge bA
git merge bA
git merge bB
git merge bB
git merge bC
git merge bC
If there are conflicts you should fix it(manually or using a mergetool), but as you said there are no conflicts, so we say that bA bB and bC
are now all in f-merge-his-repo
如果有冲突,你应该修复它(手动或使用合并工具),但正如你所说没有冲突,所以我们说bA bB and bC
现在都在f-merge-his-repo
then, just simply merge f-merge-his-repo
into your master branch
然后,只需简单地合并f-merge-his-repo
到您的主分支
You should first switch to the master branch.
git checkout master
您应该首先切换到主分支。
git checkout master
And then merge f-merge-his-repo
git merge f-merge-his-repo
然后合并 f-merge-his-repo
git merge f-merge-his-repo
or if you prefer a none fast forward merge
git merge --no-ff f-merge-his-repo
或者如果您更喜欢无快进合并
git merge --no-ff f-merge-his-repo
After all, delete these branches.
毕竟,删除这些分支。
git branch -d bA
git branch -d bA
git branch -d bB
git branch -d bB
git branch -d bC
git branch -d bC
git branch -d f-merge-his-repo
git branch -d f-merge-his-repo
You should really take a look at pro-git
here. It is a simple book which shows you everything you need with git in your daily work, and believe me, once you get used of git bash, you will find all of these git GUI's frustrated(except viewing the log, I use gitk to view and analyse the log)
你真的应该看看pro-git
这里。这是一本简单的书,它向你展示了你在日常工作中使用 git 所需的一切,相信我,一旦你习惯了 git bash,你会发现所有这些 git GUI 的挫败感(除了查看日志,我使用 gitk 查看并分析日志)
Last tip:
最后提示:
A good way to remember git merge
and git rebase
is like
一个很好的方式来记住git merge
和git rebase
像
Merge is merging another branch TOyour current branch (of course you can name both branches, but the default syntax is merge the branch to your current branch)
Merge 正在将另一个分支合并到您当前的分支(当然您可以命名这两个分支,但默认语法是将分支合并到您的当前分支)
so you should always switch to the main branch and merge others branch
所以你应该总是切换到主分支并合并其他分支
git checkout master
git checkout master
git merge their-branch --no-ff
or
git merge their-branch
git merge their-branch --no-ff
或者
git merge their-branch
And rebase is rebasing your current branch ONanother branch(usually the main branch)
和底垫的基础重建当前分支ON另一个分支(通常是主分支)
git checkout feature-branch
git checkout feature-branch
git rebase master
git rebase master