Git:如何从一个分支挑选提交并为另一个分支创建拉取请求?

Mig*_*hty 21 git bitbucket git-flow

我有两个分支机构dev& master. 我正在使用位桶。

我需要从开发分支中挑选一些提交。

然后需要为master分支创建拉取请求。

由于我的dev环境有很多东西,其中一些无法直接合并到master.

因此,从分支中获取提交 <id 1>, <id 2> dev。把他们带到一起。创建拉取请求以与master分支合并。

MaD*_*MaD 36

您可以使用

git cherry-pick <commit id>

选择特定的提交

关闭循环并从 master 发出 PR。我们可以执行以下步骤:

假设在master分支上:

git checkout -b myNewBranch // this will create a new branch named myNewBranch
git cherry-pick <commitID 1> // this will take the commit with the commit ID 1 and 
                             // attempt to place it on top of the master branch. 
                             // Note however, there might be conflicts to resolve
git cherry-pick <commitID 2> // this will take the commit with the commit ID 2 and place on top of the master branch
git push origin/<some branch name> // will push the changes to remote. Usually origin/<local branch name>
Run Code Online (Sandbox Code Playgroud)

然后,您可以根据您的平台发出拉取请求。所以它可以来自 GUI。无论是在 GitHub 平台还是 DevAzure 等上。在您的情况下通过 BitBucket GUI。

旁注:上述步骤是为了简单起见而制定的。也可以用一根线进行樱桃采摘。就像这样:

git cherry-pick <commitID 1> <commitID 2>
Run Code Online (Sandbox Code Playgroud)


小智 6

Fork original-repo as "your-repo"

git clone your-repo
cd your-repo
git checkout dev
git pull //to get all your commits to local
git checkout master
git pull //to make sure branch is upto date
git cherry-pick commit-id
git push //commits the cherry-picked commits to the master branch of forked repo

Raise PR from Forked repo "your-repo" master branch to "original-repo" master branch
Run Code Online (Sandbox Code Playgroud)