Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
505 views
in Technique[技术] by (71.8m points)

git - 如何从另一个分支完全替换Git中的master分支? [重复](How to replace master branch in Git, entirely, from another branch? [duplicate])

Possible Duplicate:

(可能重复:)
Make the current Git branch a master branch

(将当前的Git分支设为主分支)

I have two branches in my Git repository:

(我的Git存储库中有两个分支:)

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

    (seotweaks (最初由master创建))

I created seotweaks with the intention of quickly merging it back into master .

(我创建了seotweaks ,旨在将其快速合并回master 。)

However, that was three months ago and the code in this branch is 13 versions ahead of master .

(但是,那是三个月前的事,该分支中的代码比master早13个版本。)

It has effectively become our working master branch as all the code in master is more or less obsolete now.

(这实际上已经成了我们的工作主分支中的所有代码master或多或少过时了。)

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 ?

(您知道我如何用seotweaks中的内容替换master分支的所有内容吗?)

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

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

  ask by Jason translate from so

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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

(您应该能够使用“我们的”合并策略,用seotweaks覆盖master,如下所示:)

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

The result should be your master is now essentially seotweaks.

(结果应该是您的主人现在基本上是seotweaks。)

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

(( -s ours--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.

(这样可以解析任意数量的head,但是合并的结果树始终是当前分支head的树,有效地忽略了所有其他分支的所有更改。)

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.

(请注意,这与递归合并策略的-Xours选项不同。)

Update from comments: If you get fatal: refusing to merge unrelated histories , then change the second line to this: git merge --allow-unrelated-histories -s ours master

(注释更新:如果您致命: refusing to merge unrelated histories ,然后将第二行更改为:git merge --allow-unrelated-histories -s ours master)


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

1.4m articles

1.4m replys

5 comments

57.0k users

...