[英]How do I make my git branch into the master without merging?
I created a branch off the master to do some major changes to the project and now I want to make this branch the master, ie overwrite what's in the master (which has had some changes since) with what's in my branch. 我在master上创建了一个分支,以对项目进行一些重大更改,现在我想将该分支作为master,即用我的分支中的内容覆盖master中的内容(此后进行了一些更改)。 What's the best way of doing this in git?
在git中执行此操作的最佳方法是什么?
Update: I should have explained that I'm the only user right now. 更新:我应该解释说我是目前唯一的用户。 I'm using GitHub for my repository.
我将GitHub用于我的存储库。
While being on the tip of your new branch: 在新分支的顶端:
git branch -f master
git checkout master
Branches are just moving labels in Git. 分支只是在Git中移动标签。 Just create the
master
branch on the checked out commit. 只需在签出的提交上创建
master
分支即可。 Normally git would complain, as master
already exists. 通常git会抱怨,因为
master
已经存在。 Hence the force -f
option. 因此,使用了
-f
选项。
If you want to preserve the old master for whatever unforeseen reason, just put another branch on it before: 如果您出于任何不可预见的原因想要保留旧版母版,只需在其上放一个分支即可:
git branch old_master master
git branch -f master
git checkout master
You can reset any branch to any commit using git reset
. 您可以使用
git reset
将任何分支重置为任何提交。 In your case you probably want to do: 在您的情况下,您可能想要执行以下操作:
git checkout master
git tag old-master
git reset --hard otherbranch
gitk --all
The actual work is don by git reset
the tag is optional for reference in case you later need some change from your old master branch. 实际工作是通过
git reset
进行的,如果以后需要从旧的master分支进行更改,则该标记是可选的以供参考。 gitk
is a nice way to check if everything looks the way you planned it to be. gitk
是检查一切是否看起来像您计划的样子的好方法。
Be aware that this works only locally. 请注意,这仅在本地有效。 If you need to update a remote repository you probably need a forced push and might upset any other users of your repository.
如果您需要更新远程存储库,则可能需要强制推送,并且可能会使存储库的其他任何用户都不满意。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.