通过特定的提交创建PR [英] Creating a PR from a specific commit
问题描述
我想通过一次提交来创建PR,所以我用commit SHA签出一个新分支,
I want to create a PR with a single commit, so I checkout a new branch with commmit SHA,
git checkout -b new-branch 8517c80183607461ea
如何从此处创建PR?
推荐答案
由于Git分支的工作方式,仅凭单个提交进行分支是不够的.您可能会拖入更多提交.
Because of the way Git branches work, it's not enough to make a branch off a single commit. You might drag in more commits.
例如,假设您的存储库如下所示.
For example, let's say your repository looks like this.
A - B - C [master]
\
D - E - F [feature]
master
和feature
只是指向提交的标签. master
指向提交C.feature
指向提交F.
master
and feature
are just labels pointing to a commit. master
points at commit C. feature
points at commit F.
Git提交不是孤立存在的.他们与他们一起度过了整个历史.没有E,D,C,B和A的情况下F不能存在.如果按feature
,则F会将E和D一起带来(假设C已被推动).
Git commits do not live in isolation. They take their whole history with them. F cannot exist without E, D, C, B, and A. If you push feature
then F will bring E and D along with it (assuming C is already pushed).
假设您要发送仅E的PR.因此您在E上建立了一个分支.
Let's say you want to send a PR of only E. So you make a branch at E.
$ git checkout -b new-branch E
A - B - C [master]
\
D - E [new-branch]
\
F [feature]
完成的所有操作都会创建一个名为new-branch
的标签,该标签指向提交E.提交的结构保持不变.如果您再按new-branch
,它将与D一起拖动.这就是为什么有时当您认为您只推送少量提交时,PR包含更多提交的原因.
All that's done is created a label called new-branch
pointing to commit E. The structure of the commits remains the same. If you then push new-branch
it will drag D along with it. This is why sometimes when you think you're pushing only a few commits the PR contains many more commits.
为了真正只推送一个提交,您需要将其与历史分离.您可以使用 git cherry-pick
进行此操作.这基本上就是提交,将其转换为补丁,然后在其他地方对其进行补丁.
In order to really push just one commit, you need to detach it from its history. You can do this with a git cherry-pick
. This basically takes the commit, turns it into a patch, and patches it somewhere else.
返回到原始存储库...
Going back to your original repository...
A - B - C [master]
\
D - E - F [feature]
您将在master
上创建一个新分支.
You'd make a new branch off master
.
$ git checkout -b new-branch master
[new-branch]
A - B - C [master]
\
D - E - F [feature]
(请注意,除了指向C的新分支标签外,其他都没有更改.)
(Note that nothing changed except a new branch label was made pointing at C.)
然后选择E.这将把E复制为C上的新提交.可能存在冲突,请按常规解决.
Then cherry pick E. This will copy E as a new commit on top of C. There may be conflicts, resolve them as normal.
$ git cherry-pick E
E1 [new-branch]
/
A - B - C [master]
\
D - E - F [feature]
现在您可以按new-branch
键,只有E1出现在PR中.
Now you can push new-branch
and only E1 will be in the PR.
这篇关于通过特定的提交创建PR的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!