📅  最后修改于: 2023-12-03 15:30:55.194000             🧑  作者: Mango
As a developer, you may need to create a new branch in Git from a specific commit. This can be useful if you need to start working on a new feature or fix a bug in an older commit.
In this tutorial, we'll show you how to create a new branch from a specific commit using the shell/bash command line in a Git repository.
Before we get started, you'll need the following:
cd
command.cd /path/to/repository
git log
command to list all the commits in the repository. Take note of the commit ID you want to create the branch from.git log
You'll see output similar to the following:
commit 38e1d46c74f1478430f7db356ce98adf3e70ee9b
Author: John Doe <johndoe@example.com>
Date: Mon Oct 25 17:01:00 2021 +0000
Updated README file
git branch
command to create a new branch from the commit ID you noted in Step 2. Replace <new-branch-name>
with your desired branch name.git branch <new-branch-name> 38e1d46c74f1478430f7db356ce98adf3e70ee9b
You'll see output similar to the following:
* main
new-branch-name
git checkout
command.git checkout <new-branch-name>
You'll see output similar to the following:
Switched to branch 'new-branch-name'
Congratulations, you've successfully created a new Git branch from a specific commit!
In this tutorial, you learned how to create a new Git branch from a specific commit using the shell/bash command line. This can be useful when you need to start working on a new feature or fix an older bug. Remember to always use Git commands carefully and double-check before executing any critical operations.