如果我有N个提交,我如何从N-3个提交分支?


当前回答

只需运行:

git checkout -b branch-name <commit>

例如:

git checkout -b import/january-2019 1d0fa4fa9ea961182114b63976482e634a8067b8

带有参数-b的checkout命令将创建一个新分支,并将您切换到该分支

其他回答

这将使用一个命令创建分支:

git push origin <sha1-of-commit>:refs/heads/<branch-name>

我更喜欢这种方式,因为它会立即创建分支(之后不需要额外的push命令)。

使用提交哈希创建分支:

git branch branch_name <commit-hash>

或使用符号引用:

git branch branch_name HEAD~3

要在创建分支时签出分支,请使用:

git checkout -b branch_name <commit-hash or HEAD~3>

还没人提到git开关?

您可以执行以下操作:

git checkout<commit hash>

或使用符号引用:

git结帐头~3

然后:

git开关-c我的新功能分支

要在github.com上执行此操作:

转到您的项目。单击“提交”。单击要从中分支的提交上的<>(“浏览历史记录中此时的存储库”)。单击左上方的“树:xxxxxx”。就在语言统计栏下方,您将看到“查找或创建分支”选项(只需在那里键入新的分支名称)

git checkout -b <branch-name> <sha1-of-commit>