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


当前回答

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

其他回答

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

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

使用源树[当前使用的版本:3.1.3]

在源树中打开历史记录

它将在主窗口中列出所有提交右键单击所需的提交,然后单击分支。。。选项在新窗口中为分支指定名称,然后单击“创建分支”。新的分支(系统本地)将与其他现有分支一起出现在左侧,您可以将其推到源位置以将其放到存储库中,这样其他用户就可以使用它。

如果您正在寻找基于命令行的解决方案,可以忽略我的答案。我建议你使用GitKraken。这是一个非凡的git UI客户端。它在主页上显示Git树。你可以看看他们,知道项目的进展。只需选择一个特定的提交,右键单击它并选择“在此处创建分支”选项。它将提供一个文本框,用于输入分支名称。输入分支名称,选择“确定”,即可设置。它真的很容易使用。

一个很好的相关问题是:你怎么用git的--help选项来解决这个问题?让我们试试看:

git branch --help

我们看到这样的输出:

NAME
       git-branch - List, create, or delete branches    

SYNOPSIS
       git branch [--color[=<when>] | --no-color] [-r | -a]
               [--list] [-v [--abbrev=<length> | --no-abbrev]]
               [--column[=<options>] | --no-column]
               [(--merged | --no-merged | --contains) [<commit>]] [--sort=<key>]
               [--points-at <object>] [<pattern>...]
       git branch [--set-upstream | --track | --no-track] [-l] [-f] <branchname> [<start-point>]
       git branch (--set-upstream-to=<upstream> | -u <upstream>) [<branchname>]
       git branch --unset-upstream [<branchname>]
       git branch (-m | -M) [<oldbranch>] <newbranch>
       git branch (-d | -D) [-r] <branchname>...
       git branch --edit-description [<branchname>]

Gobbledegook。

在随后的文本中搜索单词“commit”。我们发现:

   <start-point>
       The new branch head will point to this commit. It may be given as a branch name, a
       commit-id, or a tag. If this option is omitted, the current HEAD will be used instead.

我们正在前进!

现在,关注这一行官样文章:

git branch [--set-upstream | --track | --no-track] [-l] [-f] <branchname> [<start-point>]

将其概括为:

git branch <branchname> [<start-point>]

完成了。

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

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