使当前的Git分支成为主分支 [英] Make the current Git branch a master branch

查看:118
本文介绍了使当前的Git分支成为主分支的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Git中有一个仓库。我做了一个分支,然后对master和分支进行了一些修改。

然后,在几十次提交之后,我意识到分支比状态好得多主人,所以我想分支成为主人,无视主人的变化。



我无法合并它,因为我不想保留主人的变化。我应该怎么做?



Extra :在这种情况下,'old'master已经是 push code> -ed到另一个存储库,如GitHub。这是怎么改变的?

解决方案

另外两个答案的问题是新主人没有老主人作为祖先,所以当你推动它时,其他人都会搞砸。这就是你想要做的:

  git checkout better_branch 
git merge --strategy =我们的主人#保留这个分支的内容,但是记录一个合并
git checkout master
git merge better_branch#fast-forward master到合并

如果您希望您的历史记录更清晰一些,我建议您在合并提交消息中添加一些信息,以明确您所做的事情。将第二行更改为:

  git merge --strategy = ours --no-commit master 
git commit#将信息添加到模板合并消息


I have a repository in Git. I made a branch, then did some changes both to the master and to the branch.

Then, tens of commits later, I realized the branch is in much better state than the master, so I want the branch to "become" the master and disregard the changes on master.

I cannot merge it, because I don't want to keep the changes on master. What should I do?

Extra: In this case, the 'old' master has already been push-ed to another repository such as GitHub. How does this change things?

解决方案

The problem with the other two answers is that the new master doesn't have the old master as an ancestor, so when you push it, everyone else will get messed up. This is what you want to do:

git checkout better_branch
git merge --strategy=ours master    # keep the content of this branch, but record a merge
git checkout master
git merge better_branch             # fast-forward master up to the merge

If you want your history to be a little clearer, I'd recommend adding some information to the merge commit message to make it clear what you've done. Change the second line to:

git merge --strategy=ours --no-commit master
git commit          # add information to the template merge message

这篇关于使当前的Git分支成为主分支的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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