如何从另一个分支完全替换git中的master分支? [英] How to replace master branch in git, entirely, from another branch?

查看:753
本文介绍了如何从另一个分支完全替换git中的master分支?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


可能存在重复:

将当前分支更改为git中的母版


我在git repo中有两个分支:


  1. master

  2. seotweaks最初来自主人)

我创建了 seotweaks ,目的是快速合并它回到 master 中,但是这是3个月前的版本,而且这个分支中的代码是 master 之前的13个版本,它已经成为我们的工作主分支,因为 master 中的所有代码现在已经或多或少已经过时。



我知道的非常糟糕的做法,经验教训。

你知道我怎样才能取代所有的内容 master 分支中的 seotweaks



我可以删除 master 中的所有内容并进行合并,但这并不是最佳实践。

解决方案

  

> git checkout seotweaks
git merge -s our master
git checkout master
git merge seotweaks

结果应该是你的主人现在基本上是seotweaks。

-s我们的的缩写 - strategy = our

文档关于'我们'的策略:


这解决了任何数量的头,但合并的结果树总是当前分支负责人实际上忽略了来自所有其他分支的所有变更。它是用来取代侧枝的旧发展历史。请注意,这与递归合并策略的-Xours选项不同。



Possible Duplicate:
Change the current branch to master in git

I have two branches in my git repo:

  1. master
  2. seotweaks (created originally from master)

I created seotweaks with the intention of quickly merging it back into master, however that was 3 months ago and the code in this branch is 13 versions ahead of master, it has effectively become our working master branch as all the code in master is more or less obsolete now.

Very bad practice I know, lesson learned.

Do you know how I can replace all of the contents of the master branch with those in seotweaks?

I could just delete everything in master and merge, but this does not feel like best practice.

解决方案

You should be able to use the "ours" merge strategy to overwrite master with seotweaks like this:

git checkout seotweaks
git merge -s ours master
git checkout master
git merge seotweaks

The result should be your master is now essentially seotweaks.

(-s ours is short for --strategy=ours)

From the docs about the 'ours' strategy:

This resolves any number of heads, but the resulting tree of the merge is always that of the current branch head, effectively ignoring all changes from all other branches. It is meant to be used to supersede old development history of side branches. Note that this is different from the -Xours option to the recursive merge strategy.

这篇关于如何从另一个分支完全替换git中的master分支?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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