Git:将master合并到新分支并清除master(Git: merge master to new branch and clear out master)

我想知道是否有人可以向我解释如何将GIT合并到一个新分支,然后清除master以获得master clean工作目录。

换句话说:master - > PHP,因为master现在将拥有Python。

I was wondering if somebody could explain to me how to GIT merge master into a new branch and then clear out master as to have master clean working directory.

In other words: master -> PHP since master will now have Python.

最满意答案

一个解决方案是,如果还没有人克隆你的回购,那么:

创建一个当前master的PHP分支 将master重置为Python提示

看到:

git checkout master git branch PHP git checkout Python git checkout -B master Python

从checkout手册页 :

git checkout -b|-B <new_branch> [<start point>]

此表单通过更新索引,工作树和HEAD来切换分支,以反映指定的分支或提交。

如果给出-B ,则创建<new_branch> (如果它不存在); 否则,它被重置。

这是交易的等价物

$ git branch -f <branch> [<start point>] $ git checkout <branch>

但是如果其他人克隆了你的repo,你需要重置master的内容,保留所有以前的提交。

对于不存在的merge -s theirs这是一个很好的例子( merge -s theirs丢弃你当前的内容并将其替换为另一个分支,如巡回案例中的Python ):

有关更多信息,请参阅“ git命令将一个分支设置为另一个分支 ”。 (首先将PHP分支放在master当前所在的位置,如上所述:该位不会改变,并标记PHP更新需要从现在开始的位置)

One solution would be, if nobody has cloned your repo yet, to:

make a PHP branch where master currently is reset master to the Python tip

See:

git checkout master git branch PHP git checkout Python git checkout -B master Python

From the checkout man page:

git checkout -b|-B <new_branch> [<start point>]

This form switches branches by updating the index, working tree, and HEAD to reflect the specified branch or commit.

If -B is given, <new_branch> is created if it doesn’t exist; otherwise, it is reset.

This is the transactional equivalent of

$ git branch -f <branch> [<start point>] $ git checkout <branch>

But if others have cloned your repo, you need to reset the content of master, keeping all the previous commits.

That would be a good case for the non-existent merge -s theirs (where your discard your current content and replace it with the one of another branch, like Python in tour case):

See "git command for making one branch like another" for more. (and start first by making the PHP branch where master currently is, like above: that bit doesn't change and will mark where PHP updates need to go from now on)

更多推荐