用git中的另一个分支覆盖master中的所有内容 [英] overwrite everything in master with another branch in git

查看:990
本文介绍了用git中的另一个分支覆盖master中的所有内容的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在git repo中有一个非常过时的master分支。我所有的工作都在另一个分支完成。将两者合并的最佳方式是什么?我不在乎任何东西,它是过时的方式。谢谢

I have a very out of date master branch in git repo. all my work has been done in another branch. What is the best way to merge the two? I don't care about anything in master, it is way out of date. Thanks

推荐答案

如果您在丢失主分支的历史记录方面很好,您只需让 master 指向当前分支的头部(不要覆盖 master - 分支 - 本身):

If you are fine with losing the history of your master branch you just let master point to the head of your current branch (your don't "overwrite" master - the branch - per se):

git checkout yourotherbranch
git branch -D master
git checkout -b master

当然,如果您有一个远程克隆,那么您必须

Of course if you have a remote clone, you'll then have to

git push -f origin master 

Nota bene 适用于替换整个 master 分支并抛出旧的 master 正如标题所示。
否则,你应该罚款 git merge master --strategy = ours

Nota bene: this specifically applies to replacing the whole of your master branch and throwing the old master away as the title suggests. Otherwise, you should be fine with git merge master --strategy=ours.

这篇关于用git中的另一个分支覆盖master中的所有内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆