git 如何将一个远程分支合并到另一个远程分支?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/23336221/
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
How to merge one remote branch into another remote branch?
提问by Zorgiev
I would like to know how to merge one remote branch into another remoter branch and have the previous one removed right after the merge applied.
我想知道如何将一个远程分支合并到另一个远程分支,并在应用合并后立即删除前一个分支。
回答by chaiyachaiya
From what I understand, you have one remote foo, containing branch_1and branch_2. First, we can't do merge operation remotly. We have to track the remote repository, do the operation we want locally (such as merging branches) and then push our new snapshot to the server.
据我了解,您有一个远程foo,其中包含branch_1和branch_2。首先,我们不能远程进行合并操作。我们必须跟踪远程存储库,在本地执行我们想要的操作(例如合并分支),然后将我们的新快照推送到服务器。
Ie:
IE:
- git clone [repo_adress]
- git clone [repo_address]
You are on the master branch.
你在主分支上。
- You can then checkout or create other branches and do your work in it.
- 然后,您可以结帐或创建其他分支并在其中进行工作。
Now suppose we have the two branches branch_1and branch_2. You want to merge branch_1 into branch_2 and then delete branch_1.
现在假设我们有两个分支branch_1和branch_2。您想将 branch_1 合并到 branch_2 中,然后删除 branch_1。
You checkout to branch_2 and then merge branch_1 with it:
您结帐到 branch_2 然后将 branch_1 与它合并:
$ git checkout branch_2
$ git merge branch_1
From there either the merge is smooth or you've got conflict. Once the merge is done, you can delete the merged branch i.e branch_1by doing:
从那里要么合并顺利,要么你有冲突。合并完成后,您可以通过执行以下操作删除合并的分支,即branch_1:
$ git branch -d branch_1
And then push your work:
然后推动你的工作:
$ git push
In case branch_2 doesn't exist on the remote, you've got to create it:
如果遥控器上不存在 branch_2,则必须创建它:
$ git push -u foo branch_2
Note that deleting branch_1 locally doesn't delete it remotely (considering that it exists on the remote). To do so, we are going to say to git: "push nothing to the branch i want to delete" ie:
请注意,在本地删除 branch_1 不会远程删除它(考虑到它存在于远程)。为此,我们将对 git 说:“什么都不推送到我想删除的分支”,即:
$ git push remote_name :branch_name
To read like git remote push remote_name "nothing":branch_name.
读起来像git remote push remote_name "nothing":branch_name。
Now is there any mean to do it automatically?
现在有什么办法可以自动完成吗?
I don't know (although I would investigate post merge "git hook"), but I'm not sure we ought to wish it. Deleting branches on remote is somewhat hazardous. Doing so manually is a good way to be sure of what we are doing.
我不知道(虽然我会调查合并后的“git hook”),但我不确定我们是否应该希望它。删除远程分支有点危险。手动执行此操作是确定我们在做什么的好方法。
回答by Riddhi
You can switch to the tracking branch(a local branch which represents your remote branch) in which you want to merge another branch by using the following command
您可以使用以下命令切换到要合并另一个分支的跟踪分支(代表远程分支的本地分支)
git checkout origin/name_of_your_branch
After that merge the another remote branch
之后合并另一个远程分支
git merge origin/brach_name_you_wanted_to_merge
After that, if any conflicts occur, solve it. and after that just commit and push.
之后,如果发生任何冲突,请解决它。之后就提交并推送。
and now checkout
to your local branch. by the following command
现在checkout
到您当地的分支机构。通过以下命令
git checkout name_of_your_brnach
After that pull the origin by using git pull
command. that's it.
之后使用git pull
命令拉原点。就是这样。
回答by Akash Agrawal
You can pull them to your local. Do a merge and push it. To delete the redundant branch thereafter, just run
你可以把它们拉到你的本地。进行合并并推送它。此后要删除冗余分支,只需运行
git push origin :<branch_to_delete>
For example, if you want to delete a branch A
例如,如果要删除分支 A
git push origin :A