简体   繁体   English

如何在不合并的情况下使git分支成为主节点?

[英]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.

相关问题 我用于将分支与主分支合并的git代码实际上有什么作用? - what does this git code that I use for merging my branch with master branch actually do? 如何在不与主分支合并的情况下从Git分支测试代码? - How to test code from a Git branch without merging it with master branch? 使用git扩展如何在不更改功能分支的情况下将我的功能分支合并到主分支中? - Using git extension how do I merge my feature branch into the master branch without changing my feature branch? 我在git的master分支中搞砸了,创建了一个新分支,如何使该分支成为新的master? - I messed up in my master branch in git, created a new branch, how to make this branch new master? 如何在不实际合并的情况下“合并” git分支 - How do I 'merge' a git branch without actually merging it 在git中,如何将主指针(分支)指向另一个提交而不合并? - In git how do you point the MASTER pointer(branch) to another commit without merging? 如何将我的 Git 'master' 分支重命名为 'release'? - How do I rename my Git 'master' branch to 'release'? Git:我如何知道我打开的文件是主文件还是在分支中 - Git: How do I know if my open file is master or in a branch 如何重置master并将分支保留在git中? - How do I reset master and keep my branch in git? 如何制作远程git分支的副本(不与我现有的分支合并)? - How to make a copy of a remote git branch (without merging with my existing branch)?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM