简体   繁体   English

Git - 将分支移动到 master

[英]Git - move branch to master

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.我只想用我分支的内容替换 master 的内容。 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.一种方法是检查分支和母版,删除母版的内容并将内容从分支复制到母版,然后将结果推送到母版。

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?有人知道怎么做吗?

You can use the following command to have master point to a new location:您可以使用以下命令让 master 指向新位置:
git branch -f master branchToMoveMasterTo

What this is actually doing is creating a new branch called master that points to branchToMoveMasterTo .这实际上是在创建一个名为master的新分支,该分支指向branchToMoveMasterTo Since we already have a branch called master, we need the -f flag to say we want to delete the original master由于我们已经有一个名为 master 的分支,我们需要-f标志来表示我们要删除原来的master

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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