根据当前分支创建新分支以使用新功能 [英] Create new branch based on current branch to work on a new feature
问题描述
如何在git
中创建新分支以开始使用新功能?
How do I create a new branch in git
to begin work on a new feature?
我希望新分支与当前分支重复(即新分支的HEAD应该与当前HEAD相同).
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).
问题区分:
- 从另一个分支在Git中创建分支似乎是相关的,但实际上是关于分支被快速合并的原因.
- 如何创建远程Git分支?是关于在远程上创建新分支.
- Create a branch in Git from another branch seems 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.
推荐答案
TL; DR:
要在名为FEATURE
的新分支上创建并开始工作,请执行以下操作:
To create and start work on a new branch called FEATURE
, you do:
git checkout -b FEATURE
详细说明
要创建一个名为FEATURE
的分支:
To create a branch called FEATURE
:
git branch FEATURE
但是,这不会更改您当前的分支.
However, this does not change your current branch.
然后您可以checkout
新创建的分支(这意味着使其成为您当前正在使用的分支:
You can then checkout
the newly created branch (which means make to it the branch you're currently working on:
git checkout FEATURE
(您可以在git branch --list
的输出中看到带有*
标记的当前分支.)
(You can see the current branch marked with a *
in the output of git branch --list
.)
通常,您要在刚刚创建的分支中开始工作,因此这两个命令的等效快捷键是git checkout -b FEATURE
,它会创建一个新分支,然后在其上执行checkout
.
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.
这篇关于根据当前分支创建新分支以使用新功能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!