git 实现pr功能
I love the traditional GitHub workflow of receive pull request, pull down pull request to test, and merge the pull request. GitHub makes the first and the third steps easy but pulling down pull requests from new contributors requires some boilerplate work that annoys me...
我喜欢传统的GitHub工作流程,即接收拉取请求,拉下拉取请求进行测试以及合并拉取请求。 GitHub使第一步和第三步变得容易,但是要撤消新贡献者的请求就需要一些样板工作,这使我很烦。
...namely navigating to their fork and copying the fork address so that I can do:
...即导航到他们的fork并复制fork地址,以便我可以执行以下操作:
git pull https://github.com/some-new-user/repo.git branch-name
And since you don't know if the author will be contributing more in the future, there's no point in adding them as a remote (via git remote add
) -- you'll just muddy up your remote listing.
而且由于您不知道作者将来是否会做出更多贡献,因此将它们添加为远程对象(通过git remote add
)没有任何意义-您只会弄混远程列表。
After years of this annoying dance I've found TeamPorcupine's awesome git alias for easily pulling down pull requests:
经过多年这种令人讨厌的舞蹈,我发现了TeamPorcupine的超赞git别名,可以轻松拉出拉取请求:
git config --global --add alias.pr '!f() { git fetch -fu ${2:-upstream} refs/pull/$1/head:pr/$1 && git checkout pr/$1; }; f'
git config --global --add alias.pr-clean '!git checkout master ; git for-each-ref refs/heads/pr/* --format="%(refname)" | while read ref ; do branch=${ref#refs/heads/} ; git branch -D $branch ; done'
The first alias above, git pr
, allows you to pull down a pull request by ID, creating an new branch for it:
上面的第一个别名git pr
允许您按ID下拉请求请求,为其创建一个新分支:
~/Projects/debugger.html (master) $ git pr 4862
From https://github.com/devtools-html/debugger.html
* [new ref] refs/pull/4862/head -> pr/4862
Switched to branch 'pr/4862'
~/Projects/debugger.html (pr/4862) $
The second alias, git pr-clean
, deletes all branches created with git pr
:
第二个别名git pr-clean
,删除使用git pr
创建的所有分支:
~/Projects/debugger.html (pr/4862) $ git pr-clean
Switched to branch 'master'
Your branch is ahead of 'origin/master' by 190 commits.
(use "git push" to publish your local commits)
husky > npm run -s postcheckout (node v8.5.0)
Deleted branch pr/4862 (was 10fe5049).
~/Projects/debugger.html (master) $
Note: You must have a remote called upstream
which points to the upstream repo.
注意:您必须具有一个称为upstream
的远程站点,该远程站点指向上游存储库。
I can't tell you how happy I am to have this pr
git alias, and how much of a bonus the pr-clean
alias is. Checking out PRs will be so much faster and I can focus more on code and functional review than process!
我无法告诉您拥有此pr
git别名对我有多高兴,以及pr-clean
别名有多少奖金。 检出PR的速度将如此之快,我可以将精力更多地放在代码和功能审查上,而不是过程上!
git 实现pr功能