Git从以前的提交范围创建分支? [英] Git create branch from range of previous commits?
问题描述
我为一个操作系统项目提交了一堆提交,并且我只想说出最后一个提交20提交到另一个分支,以便我可以提出请求。
I have a bunch of commits for an OS project and I want to pull out just the last say 20 commits into another branch so I can pull request.
我可以这样做吗?原因是我可能有150次提交,但其中大部分都是为了一个更大的贡献,这还没有准备好。但下一个版本即将发布。
How could I do this? The reason being is I have maybe 150 commits, but most of those are for a much larger contribute, which isn't ready yet. But the next version is being released soon.
谢谢!
Thanks!
推荐答案
你可以用 cherry-pick
来做到这一点。如果您的 long_branch
的历史记录如下所示:
You can do this with cherry-pick
. If your history of long_branch
looks like this:
A-B <-- master
\
C-D-E-F-G-H <-- long_branch
将F到H的内容移动到另一个分支,比如 short_branch
,它基于 master
:
and you want to move the contents of, say, F through H to a different branch, say, short_branch
, which is based off of master
:
git checkout master -b short_branch
给出的是
which gives
A-B <-- master, short_branch
\
C-D-E-F-G-H <-- long_branch
然后...(注意提交范围是 E..H
;左侧不包括范围)
then... (note that the commit range is E..H
; the left side is non-inclusive for the range)
git cherry-pick E..H
给出:
F'-G'-H' <-- short_branch
/
A-B <-- master
\
C-D-E-F-G-H <-- long_branch
N注意我将新提交称为 F'
, G'
, H '
- 这是因为它们将包含与 F
相同的有效更改, G
,并且 H
,它们不会是实际的相同的提交(由于不同的父母+提交时间)。
Note that I'm referring to the new commits as F'
, G'
, H'
- this is because while they will contain the same effective changes as F
, G
, and H
, they won't be the actual same commits (due to different parents + commit times).
这篇关于Git从以前的提交范围创建分支?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!