Git create a new branch from a h
2019-02-20 本文已影响0人
JaedenKil
git branch branchName <sha1-of-commit>
# On master branch
$ git log --oneline
37f1ff2 (HEAD -> master) Add file06
fd92f0a Add file04 and file05
706ac8d (demo) Add file03
e62bfba Add file02
6dd771d Add file01
# Create a new branch named "demo01"
$ git branch demo01 706ac8d
# Checkout to demo01
$ git checkout demo01
Switched to branch 'demo01'
# Om demo01 branch
$ git log --oneline
706ac8d (HEAD -> demo01, demo) Add file03
e62bfba Add file02
6dd771d Add file01
# On master branch
$ git log --oneline
37f1ff2 (HEAD -> master) Add file06
fd92f0a Add file04 and file05
706ac8d (demo01, demo) Add file03
e62bfba Add file02
6dd771d Add file01
-
git checkout -b branchName <sha1-of-commit>
Which is equivalent togit branch branchName <sha1-of-commit>
+git checkout branchName
.