“git 分支”和“git 分支”有什么区别?和“git checkout -b”?
我使用 git checkout -b 创建一个新分支。我认为 gitbranch 做了同样的事情。 如果这两个命令有不同的话,它们有何不同?
I used git checkout -b
to create a new branch. I think that git branch
does the same thing.
How do these two commands differ, if they differ at all?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(7)
git checkout -b BRANCH_NAME
创建一个新分支并签出新分支,而gitbranch BRANCH_NAME
创建一个新分支,但将您留在同一分支上。换句话说,
git checkout -b BRANCH_NAME
会为您执行以下操作。git checkout -b BRANCH_NAME
creates a new branch and checks out the new branch whilegit branch BRANCH_NAME
creates a new branch but leaves you on the same branch.In other words
git checkout -b BRANCH_NAME
does the following for you.gitbranch
创建分支,但您仍保留在已签出的当前分支中。git checkout -b
创建一个分支并将其签出。它可以被认为是以下形式的缩写:
git branch
creates the branch but you remain in the current branch that you have checked out.git checkout -b
creates a branch and checks it out.It could be considered a short form of:
完整语法:
[FROM_BRANCH] 是可选的。如果没有 FROM_BRANCH,git 将使用当前分支。
Full syntax:
The [FROM_BRANCH] is optional. If there's no FROM_BRANCH, git will use the current branch.
gitbranch
: 显示所有分支gitbranchnewbranch
: 创建新分支git checkout -b newbranch
: 创建一个新分支并立即切换到该分支。这与git Branch newbranch
后跟git checkout newbranch
相同。git branch
: Shows all your branchesgit branch newbranch
: Creates a new branchgit checkout -b newbranch
: Creates a new branch and switches to that branch immediately. This is the same asgit branch newbranch
followed bygit checkout newbranch
.还有另一个标志需要提及,它与这些相关。
这是我最近一直在使用的一个非常有用的命令。此命令检出您指定的分支,并根据源分支重置该分支。
There is also another flag to mention, which is relative to these..
This is a very useful command that i've been using recently. This command checks out the branch you specify, and resets the branch based on the source branch.
这两个命令的形式相似(查看 git-scm 文档版本 2.11.1):
以及
后者 先执行分支命令,然后添加结账。以该形式明确引用 git-branch 的文档:
There are forms of both commands that are similar (looking at git-scm docs Version 2.11.1):
and
The latter executing the branch command first and then adding the checkout. In that form explicitly references to git-branch's doc:
本质上:
A-git 分支让您可以简单明了地创建分支。
B -git checkout -b 允许您创建一个分支并同时切换到它。
你什么时候会使用哪个?
1- gitbranch 当你想创建一个分支但保留在当前分支上时。
2- git checkout -b 当你想创建和切换时。
如果你看一下,创建一个分支并切换到它是很直观的。所以选择是你的:)
Essentially :
A-git branch lets you create a branch plain and simple.
B -git checkout -b allows you to create a branch and switch to it at the same time.
When will you use which ?
1- git branch when you want to create a branch but stay on the current branch.
2- git checkout -b when you want to create and switch.
If you look at it is intuitive to create a branch and switch to it. So the choice is yours :)