在 GitHub 上发送仅最新提交的拉取请求
我在 github 上分叉了一个项目,并成功对我的本地 master 进行了更改并推送到 github 上的原点。我想发送拉取请求,但只想包含最后一次提交。 github.com 上的拉取请求 UI 显示了最后 9 个提交,但我不知道如何过滤掉它。
我试图了解是否应该创建一个新的本地分支,检查一下并以某种方式重置或变基到上游?然后将我的 master 按 id 的最后一次提交应用到新的本地分支并将其用于拉取请求?
我正在尝试正确理解概念并找出正确的命令行来完成我需要的操作。
I forked a project on github and am successfully making changes to my local master and pushing to origin on github. I want to send a pull request, but only want to include the last commit. The pull request UI on github.com shows the last 9 commits and I don't know how to filter that down.
I was trying to understand if I should create a new local branch, check that out and somehow reset or rebase to upstream? Then apply my last commit from my master by id to the new local branch and use that for the pull request?
I'm trying to get the concepts right and figure out the right command lines to do what I need.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(7)
您基本上需要创建一个新的分支并创建一个新的分支。 樱桃-选择您想要添加到其中的提交。
之后,您将看到
github 上的分支,切换到它并可以提交包含您想要的更改的拉取请求。You need to basically create a new branch & cherry-pick the commits you want to add to it.
Afterwards, you will see
<new-branch-name>
branch on github, switch to it and can submit the pull request with the changes you want.从最新提交开始创建一个新分支,该提交也在原始存储库中:
然后使用 gitcherry-pick 获取您想要拉取请求的单个提交。如果具有此提交的分支称为
feature
并且您想要的提交是此分支中的最新提交,这将是假设此补丁应用没有冲突,您现在有了一个可以执行您的操作的分支拉取请求。
第二步,您现在需要决定如何处理您的
feature
分支。如果您尚未在此分支上发布更改,则最好的过程可能是在新分支上重新调整此分支(并删除最后一次提交,如果git rebase
没有自动完成此操作)。Create a new branch starting from the latest commit, which is also in the origin repository:
Then use
git cherry-pick
to get the single commit you want the pull request for. If the branch with this commit is calledfeature
and the commit you want is the latest commit in this branch, this will beAssuming this patch applies without conflict, you got now a branch for which you can do your pull request.
In a second step, you now need to decide what to do with your
feature
branch. If you haven't published your changes on this branch yet, the best procedure is probably rebasing this branch upon new-branch (and removing the last commit, if this is not done automatically bygit rebase
).我最终遇到了这样的情况:我分叉了一个分叉,并想将拉取请求提交回原始项目。
我有:
为此,我:
git 命令类似于:
然后我选择 my-feature-request 作为对原始项目的拉取请求的分支。
I ended up in a situation where I had forked a fork and wanted to submit a pull request back to the original project.
I had:
To do this, I:
The git commands were something like:
Then I picked my-feature-request as the branch for my pull request to the original project.
这几乎对我有用:
唯一的区别是:
我需要更改最后一行,以便 git Push 在我的 GitHub 存储库中创建上游分支,以便我可以从中制作 PR。
This almost worked for me:
The only difference was this:
I needed to change that last line so that git push would make the upstream branch in my GitHub repo so that I could make PR from it.
我已经进行了提交,我希望能够将其作为拉取请求隔离回当前分支。
所以我检查了一个新的分支
这是我的解决方案与@Kevin Hakanson的不同的地方,因为我需要将此分支重置到历史记录中我想要区别的位置
并挑选来自的提交我想创建一个独立的拉取请求
最后将其推送到远程
并拉取请求数据。
I had already made the commit which I wanted to be able to isolate as a pull request back onto the current branch.
So I checked out a new branch
And here's where my solution differs from @Kevin Hakanson's, as I need to reset this branch to the place in the history I want to diff from
And cherry-pick the commit from which I want to create an isolated pull request
Finally push it up to the remote
And pull request dat shi.
创建新的(临时)分支、挑选并为该分支创建拉取请求的解决方案并不令我满意。我不想更改我的存储库以使一组提交可用,因此我提出了以下替代方案:
首先为所有感兴趣的提交创建补丁文件:
如果感兴趣的提交恰好是您可以使用的最后一个提交< code>HEAD 而不是
。现在,您可以将补丁发送给源存储库的维护者,他们可以应用它们:
最后,这应该看起来与通过拉取请求合并临时分支相同,但在分叉存储库中没有该附加分支。
The solution to create a new (temporary) branch, cherry-pick and creating the pull request for that branch did not satisfy me. I did not want to change my repository to make a set of commits available, so I came up with the following alternative:
First create patch files for all commits of interest:
If the commit of interest happens to be the last one you can use
HEAD
instead<sha>
.Now, you can send the patches to the maintainer of the source repository, who can apply them:
Finally this should look the same as if a temporary branch was merged by a pull request, but without having that additional branch in the fork-repository.
根据 @kevin-hakanson 的回答,我编写了这个小 bash 脚本来使这个过程更容易。如果上游存储库尚不存在,它将添加它(提示您输入 URL),然后提示您输入要创建的新分支的名称以及选择该分支的提交的标签/SHA。它会检查您当前所在的分支或提交,然后隐藏所有更改,以便您可以签出新分支。合并策略保留精选提交中的更改。将新分支推送到origin(假设是远程存储库的名称)后,您之前所在的分支或提交将再次检出,并且您之前的更改会从存储中弹出。
(这在一些简单的测试中对我有用,但我不是 bash 程序员或 git 专家,所以如果我错过了一些可以更好地自动化的情况,请告诉我!)
Based on @kevin-hakanson's answer, I wrote this little bash script to make this process easier. It will add the upstream repo if it doesn't already exist (prompting you for the URL) then prompt for both the name of the new branch to create and the tag / SHA of the commit to cherry pick onto that branch. It checks what branch or commit you're currently on then stashes any changes so you can checkout the new branch. The merge strategy keeps the changes from the cherry-picked commit. After pushing the new branch to
origin
(assumed to be the name of your remote repo), the branch or commit you were on before is checked out again and your previous changes popped from the stash.(This has worked for me in a couple of simple tests, but I'm not a bash programmer or git expert, so let me know if there are cases I've missed that could be automated better!)