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


当前回答

我可以这样做:

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

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

其他回答

这是我所做的:

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

使用提交哈希创建分支:

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我的新功能分支

使用Sourcetree|最简单的方法。

首先,签出要进行特定提交以创建新分支的分支。然后查看工具栏,选择Repository>Branch。。。快捷方式是Command+Shift+B。然后选择要执行的特定提交。并给出一个新的分支名称,然后创建一个分支!

我可以这样做:

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

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