如果我有N个提交,我如何从N-3个提交分支?
当前回答
要在github.com上执行此操作:
转到您的项目。单击“提交”。单击要从中分支的提交上的<>(“浏览历史记录中此时的存储库”)。单击左上方的“树:xxxxxx”。就在语言统计栏下方,您将看到“查找或创建分支”选项(只需在那里键入新的分支名称)
其他回答
你可以在斯塔什做。
单击提交在屏幕右上方单击“标记此提交”然后,您可以从刚刚创建的标记创建新分支。
还没人提到git开关?
您可以执行以下操作:
git checkout<commit hash>
或使用符号引用:
git结帐头~3
然后:
git开关-c我的新功能分支
一个很好的相关问题是:你怎么用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>]
完成了。
在Github repo上快速执行此操作的方法如下:
从分支机构查找特定提交在SHA id旁边,单击“浏览历史记录中此时的回购”在这里,您可以从此提交创建一个新分支
使用提交哈希创建分支:
git branch branch_name <commit-hash>
或使用符号引用:
git branch branch_name HEAD~3
要在创建分支时签出分支,请使用:
git checkout -b branch_name <commit-hash or HEAD~3>
推荐文章
- 为什么我需要显式地推一个新分支?
- 如何撤消最后的git添加?
- Rubymine:如何让Git忽略Rubymine创建的.idea文件
- Gitignore二进制文件,没有扩展名
- Git隐藏错误:Git隐藏弹出并最终与合并冲突
- 了解Git和GitHub的基础知识
- 没有。Git目录的Git克隆
- 在GitHub上有一个公共回购的私人分支?
- Git与Mercurial仓库的互操作性
- 忽略git中修改(但未提交)的文件?
- “git restore”命令是什么?“git restore”和“git reset”之间有什么区别?
- Git合并与强制覆盖
- Git拉另一个分支
- 在Bash命令提示符上添加git分支
- 如何更改Git日志日期格式