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


当前回答

还没人提到git开关?

您可以执行以下操作:

git checkout<commit hash>

或使用符号引用:

git结帐头~3

然后:

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

其他回答

使用提交哈希创建分支:

git branch branch_name <commit-hash>

或使用符号引用:

git branch branch_name HEAD~3

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

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

这是我所做的:

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是属于主分支的旧提交。

如果您使用的是非常直接的源代码树。

右键单击需要从中创建新分支的提交单击“分支”在对话框中键入新分支的名称,然后单击“创建分支”

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

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

我可以这样做:

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

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