创建基于另一个分支的 git 分支

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/15026864/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-10 15:34:14  来源:igfitidea点击:

Creating git branch based another branch

gitgit-branch

提问by Leszek Andrukanis

I'd like to create local branch based on other branch. For example I type:

我想基于其他分支创建本地分支。例如我输入:

git checkout -b feature1 release1.1.3

git checkout -b feature1 release1.1.3

After that I get:

之后我得到:

fatal: git checkout: updating paths is incompatible with switching branches.

fatal: git checkout: updating paths is incompatible with switching branches.

What is the problem with this ?

这有什么问题?

采纳答案by ssube

To create a branch based on another branch, the simplest way is to first checkout the base branch, then create a new branch from there. If I understand your question right, that's exactly what you want to do.

要基于另一个分支创建分支,最简单的方法是先检出基本分支,然后从那里创建一个新分支。如果我理解你的问题是正确的,那正是你想要做的。

Now, seeing as you are using the -bflag in your branching, you may have working changes that you want to keep. If that's the case, you should push them onto the stash, check out the base branch, create the new branch, and pop the stash.

现在,当您-b在分支中使用该标志时,您可能有想要保留的工作更改。如果是这种情况,您应该将它们推送到 stash,检查基本分支,创建新分支,然后弹出 stash。

回答by Arun

git branch <new-branch-name> <existing-branch-name>

回答by zs2020

Do git pullfirst to make sure all you local branches are up-to-date. And then you can cut the branch.

git pull首先确保你的本地分支上最新的。然后你就可以剪树枝了。

The syntax is

语法是

$ git checkout -b <branch> --track <remote>/<branch>

or

或者

$ git checkout <remote>/<branch> -b <branch>

回答by patthoyts

You meant git branch feature1 release1.1.3assuming you want a branch called feature1 to be based upon the release1.1.3 commit. What you called there should also work but you also have an actual folder called 'release1.1.3' in your working tree and git is getting confused about whether you mean the branch/tag or the folder.

您的意思是git branch feature1 release1.1.3假设您希望名为 feature1 的分支基于 release1.1.3 提交。您在那里调用的内容也应该有效,但是您的工作树中还有一个名为“release1.1.3”的实际文件夹,而 git 对您是指分支/标签还是文件夹感到困惑。

You could try just giving the actual commit id of release1.1.3.

您可以尝试仅提供 release1.1.3 的实际提交 ID。