1. Learn center
  2. Software Development
  3. Guides
  4. Git tutorial
  5. 如何使用 Git
  6. 如何在 Git 中使用分支
  7. 切换到一个分支
Git

Project and code management together.

Try it free

切换到一个分支

您刚才创建了一个分支;现在您需要切换到该分支,以向其添加新的提交。

使用 git checkout 命令切换到分支issue1

$ git checkout issue1
Switched to branch 'issue1'

现在,历史记录看起来像这样:

Current history

使用-b选项创建一个新的分支,并用一个指令切换到该分支。

接下来,让我们添加一个提交。将下面的粗体文本添加到myfile.txt文件中。

Anyone can learn Git with this tutorial and Backlog add: Register a change in an index

并提交更改。

$ git add myfile.txt
$ git commit -m "append description of the add command"
[issue1 b2b23c4] append description of the add command
 1 files changed, 1 insertions(+), 0 deletions(-)

现在历史记录看起来像这样:

Current history

Subscribe to our newsletter

Learn with Nulab to bring your best ideas to life