git 根据当前分支创建新分支以处理新功能
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/46706821/
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
Create new branch based on current branch to work on a new feature
提问by Tom Hale
How do I create a new branch in git
to begin work on a new feature?
如何在其中创建新分支git
以开始处理新功能?
I want the new branch to be a duplicate of the current branch (ie, the new branch's HEAD should be the same as the current HEAD).
我希望新分支是当前分支的副本(即,新分支的 HEAD 应该与当前的 HEAD 相同)。
Question differentiation:
问题区分:
- Create a branch in Git from another branchseems related but is actually about why a branch is fast-forward merged.
- How do you create a remote Git branch?is about creating a new branch on a remote.
- 从另一个分支在 Git 中创建一个分支似乎相关,但实际上是关于为什么一个分支是快进合并的。
- 如何创建远程 Git 分支?是关于在远程创建一个新分支。
回答by Tom Hale
TL;DR:
特尔;博士:
To create and start work on a new branch called FEATURE
, you do:
要在名为 的新分支上创建并开始工作FEATURE
,您需要执行以下操作:
git checkout -b FEATURE
Detailed explanation
详细说明
To create a branch called FEATURE
:
创建一个名为 的分支FEATURE
:
git branch FEATURE
However, this does not change your current branch.
但是,这不会更改您当前的分支。
You can then checkout
the newly created branch (which means make to it the branch you're currently working on:
然后checkout
,您可以创建新创建的分支(这意味着将其设为您当前正在处理的分支:
git checkout FEATURE
(You can see the current branch marked with a *
in the output of git branch --list
.)
(您可以*
在 的输出中看到标有 a 的当前分支git branch --list
。)
Generally you want to start working in the branch you have just created, so the shortcut equivalent for both commands is git checkout -b FEATURE
, which creates a new branch, then does checkout
on it.
通常,您希望在刚刚创建的分支中开始工作,因此这两个命令的等效快捷方式是git checkout -b FEATURE
,它会创建一个新分支,然后checkout
在其上执行。