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


当前回答

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

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

其他回答

使用提交哈希创建分支:

git branch branch_name <commit-hash>

或使用符号引用:

git branch branch_name HEAD~3

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

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

我可以这样做:

git branch new_branch_name `git log -n 1 --skip 3 --format=%H`

必须在其中输入跳过值。0是最新的,1是先前的,2是之前的提交,等等。

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

对于GitGUI用户,您可以可视化所有历史记录(如果需要),然后右键单击要分支的提交并输入分支名称。

这是我所做的:

C:\Users\[path]\build>git checkout -b responsivenavigation 8a75b001096536b3216022484af3026aa9c7bb5b
Switched to a new branch 'responsivenavigation'

C:\Users\jaimemontoya\[path]\app>git branch
  master
* responsivenavigation

在本例中,8a75b001096536b3216022484af3026aa9c7bb5b是属于主分支的旧提交。