如何完成这个任务?
我尝试过但不起作用的方法:
- 在PR被接受后删除分支 (PR #755)
- 在PR被接受后删除仓库 (PR #78)
更新
以下是 我的一个PR 被合并时的示例:
结果为:
如何完成这个任务?
我尝试过但不起作用的方法:
更新
以下是 我的一个PR 被合并时的示例:
结果为:
GitHub引入了一种选项,在合并时压缩提交记录,因此您可以直接从其Web界面执行此操作:
刚刚发现了Meteor团队的工作流程(巧合的是,感谢@Emily):
当您在GitHub网页界面中查看拉取请求时,会看到一个非常吸引人的“合并”按钮。永远不要使用合并按钮。它是一种有吸引力的诱因。它会导致比必要更复杂的git历史记录:如果PR是一个月前提交的,则提交的父级将是一个非常旧的修订版本,在git历史记录的图形视图中会导致比必要更多的行数。此外,如果您使用合并按钮,那意味着您从未检出代码并尝试过它!以下是更好的方法来处理拉取请求。
首先,在您的存储库中,找到.git/config
文件的[remote "origin"]
部分,并添加以下行:
fetch = +refs/pull/*/head:refs/remotes/origin/pr/*
确保在现有的fetch行之前添加它。现在,每次你git fetch,你都会得到repo中所有的Pull Requests更新!这是一次性的更改,将为您永久提供直接访问PR的权限。
然后,你只需要git checkout pr/XXX
并直接处理更改。在cherry-picking之后进行git push origin
将创建紧凑型PR:
git checkout pr/32
# ... test changes ...
git checkout master
git cherry-pick pr/32
git push
If the PR is multiple commits, the best thing to do is to check it out, rebase it onto your development branch, make whatever other changes you need, and merge it back to the development branch with an explicit merge commit. This is similar to what the GitHub merge button does, except that the merge button doesn't do the VERY IMPORTANT rebase step and so it leaves ugly spaghetti in the project's git commit history. To do this, run:
git checkout pr/32; git rebase devel; git checkout devel; git merge --ff-only pr/32
Then test and push.
If you'd like to combine some of the commits into a single commit, you can use interactive rebase by running
git rebase -i devel
instead. Some tutorials: http://gitready.com/advanced/2009/02/10/squashing-commits-with-rebase.html https://www.atlassian.com/git/tutorials/rewriting-history/git-reflogUnfortunately GitHub is not smart enough to detect that you've merged a PR by hand, so you'll need to manually comment and close the issue with a link to the relevant commit. Alternatively, make sure that the merge commit's message contains
Fixed #123
.
$ git checkout -b branch-for-pr master
$ git pull <fork url> <pr branch name>
$ git checkout master
$ git cherry-pick branch-for-pr
或者,您可以将PR分支rebase到master之上,以允许快进合并(这将跳过合并提交):
$ git checkout -b branch-for-pr master
$ git pull <fork url> <pr branch name>
$ git rebase master
$ git checkout master
$ git merge --ff-only branch-for-pr