Git - 将分支移至 master

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/10043888/
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 06:43:16  来源:igfitidea点击:

Git - move branch to master

gitgit-branchbranching-and-merging

提问by Rostyslav Druzhchenko

I have a branch with actual sources and I did not make any commits for a long time to master, and at the moment it's completely out of date. I want to just replace master's content with the content of my branch. One way to do it is to checkout both branch and master, delete master's content and copy content from branch to master, and after that push result to master.

我有一个有实际来源的分支,我很长一段时间没有提交任何内容来掌握,目前它已经完全过时了。我只想用我的分支的内容替换 master 的内容。一种方法是同时检出分支和母版,删除母版的内容并将内容从分支复制到母版,然后将结果推送到母版。

It works, but I believe there has to be some git command to do it in a simpler way.

它有效,但我相信必须有一些 git 命令才能以更简单的方式做到这一点。

Does anybody know how to do it?

有人知道怎么做吗?

回答by Andy

You can use the following command to have master point to a new location:
git branch -f master branchToMoveMasterTo

您可以使用以下命令让 master 指向一个新位置:
git branch -f master branchToMoveMasterTo

What this is actually doing is creating a new branch called masterthat points to branchToMoveMasterTo. Since we already have a branch called master, we need the -fflag to say we want to delete the original master

这实际上是在创建一个名为的新分支master,指向branchToMoveMasterTo. 因为我们已经有一个叫做 master 的分支,所以我们需要这个-f标志来说明我们要删除原来的master