简体   繁体   English

如何使git分支成为新主人?

[英]How to make a git branch the new master?

A few days ago, I created a new git branch using: 几天前,我使用以下命令创建了一个新的git分支:

git checkout -b release-1_5

Since creating that new branch, I've made additional changes & commits to it. 自创建新分支以来,我进行了其他更改并提交了该分支。

I'm the only developer, and no changes have been made to the actual 'master' in the meantime. 我是唯一的开发人员,在此期间,实际的“ master”没有任何更改。 I want to make the current state of the "release-1_5" branch the new master, and make 'master' the new working (HEAD?) branch, so that if I later do something like: 我想将“ release-1_5”分支的当前状态设为新的master,并将“ master”作为新的工作中的(HEAD?)分支,以便以后执行以下操作:

git checkout -b release-1_6

it will create a new branch that branches off from master 它将创建一个新分支,该分支从master分支出来

I know I could probably just keep doing "git checkout -b {new-branch-name}" (creating a linear branch-of-a-branch(-of-a-branch[-...]), but I'm pretty sure that would screw up Git's subway-like branch diagram. 我知道我可能可以继续做“ git checkout -b {new-branch-name}”(创建一个线性分支(-of-branch [-...]),但是我我很确定这会搞乱Git的地铁分支图。

If it matters, at the moment, the repo is entirely local, so there's no pulling/pushing or origin to worry about. 如果重要的话,目前,回购完全是本地的,因此没有拉/推或起源的烦恼。

You're describing a simple merge of release-1_5 back onto master . 您正在描述将release-1_5重新合并回master的简单合并。 Since master has no new commits, it'll be a fast-forward merge. 由于master没有新的提交,它将是一个快速合并。

$ git checkout master
$ git merge release-1_5

And that's it. 就是这样。 You can optionally delete the release-1_5 branch after that if you like. 之后,您可以根据需要选择删除release-1_5分支。

I would not play with deleting branches. 我不会玩删除分支。
What you want to do is to simply move latest commit from the release-1_5 to master . 您要做的只是将最新的提交从release-1_5移到master

git checkout master
git merge release-1_5
git checkout master
git reset --hard HEAD~3 # Go back 3 commits. You *will* lose uncommitted work.

Hope this helps 希望这可以帮助

git checkout release-1_5
git merge --strategy=ours master  # This will keep content of branch
git checkout master
git merge release-1_5             # this will fast-forward master to the merge

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM