如何从分支的一部分创建请求请求?

时间:2019-05-21 16:56:26

标签: git

我们有一个名为“ develop”的主要共享分支,而我已经从该分支创建了一个名为“ feature”的分支。至此,我们决定只想为“功能”分支的一部分创建一个拉取请求,以便它可以返回“开发”并轻松地被其他队友查看。 “功能”分支的其余部分将不会被丢弃,并且需要在将来的某个时候将其部分合并回“开发”中。我该怎么做?

我应该在develop之外创建一个新分支,然后使用“ git checkout”仅将某些文件从“ feature”分支中拉出并将它们提交到这个新分支中(这样我就可以对其进行拉取请求) ?如果是这样,那么有比手动记住已带来的和未带来的更好的策略来带回“功能”的未来点了?

This blog post was a good reference point.

谢谢。

1 个答案:

答案 0 :(得分:1)

好吧...假设特征分支从开发中拆分后具有n个(实际上与数量无关)修订:

git checkout -b branch1 feature
git reset --soft $( git merge-base HEAD develop ) # go back to the last common revision
# at this point all files changed on develop will be on index
# reset the files that you want on the other branch only keep on index the files you want to keep on branch1
git reset filec filee # will keep filea, fileb and filed on this branch
git commit -m "branch 1 - blah blah"
# there you have your branch1 with changes on filea, fileb and filed
git checkout -b branch2 feature
git reset --soft branch1 # so that we don't need to pick the files for this branch
git commit -m "Branch2 - blah blah" # will commit changes for filec and filee

这时,修订是一个接一个的修订,如果您想将它们分开,请在先前的修订之后运行:

git rebase --onto branch1~1 branch1 branch2

这会将branch2移至并行分支。