Git 命令行上拉取请求的语法
Git syntax for pull request on the command line
我在此处查看文档:https://git-scm.com/docs/git-request-pull
但我不确定如何将它应用到我想做的事情上。我推送到名为 "fix/fixNumberHere" 的分支,我想使用拉取请求合并到名为 "mergeBranch" 的分支——如何将其应用于:
git request-pull [-p] <start> <url> [<end>]
我想你会使用这个语法:
git request-pull mergeBranch origin fix/fixNumberHere
^^^ start ^^ url ^^^ end
我认为大多数 Git 用户通常会直接在远程创建拉取请求,例如如果他们使用 GitHub 或 BitBucket 之类的东西。
根据远程存储库,git request-pull
不再是唯一的选择:借助 Git 2.29(2020 年第 4 季度)的新 server-side 挂钩,可以自动创建 PR :
"git receive-pack
"(man) 接受“git push
”的请求学会了将大部分 ref 更新外包给 新的“proc-receive
" 挂钩.
参见 commit d6edc18, commit 1702ae6, commit c6a6a01, commit 31e8595, commit b913075, commit 63518a5, commit 195d6ea, commit 15d3af5, commit 38b9197, commit 917c612 (27 Aug 2020) by Jiang Xin (jiangxin
)。
(由 Junio C Hamano -- gitster
-- in commit 6c430a6 合并,2020 年 9 月 25 日)
receive-pack
: add new proc-receive
hook
Signed-off-by: Jiang Xin
Git calls an internal execute_commands
function to handle commands sent from client to git-receive-pack
.
Regardless of what references the user pushes, Git creates or updates the corresponding references if the user has write-permission.
A contributor who has no write-permission, cannot push to the repository directly.
So, the contributor has to write commits to an alternate location, and sends pull request by emails or by other ways.
We call this workflow as a distributed workflow.
It would be more convenient to work in a centralized workflow like what Gerrit provided for some cases.
For example, a read-only user who cannot push to a branch directly can run the following git push
(man) command to push commits to a pseudo reference (has a prefix "refs/for/
", not "refs/heads/
") to create a code review.
git push origin \
HEAD:refs/for/<branch-name>/<session>
The <branch-name>
in the above example can be as simple as "master
", or a more complicated branch name like "foo/bar
".
The <session>
in the above example command can be the local branch name of the client side, such as "my/topic
".
We cannot implement a centralized workflow elegantly by using "pre-receive
" + "post-receive
", because Git will call the internal function "execute_commands
" to create references (even the special pseudo reference) between these two hooks.
Even though we can delete the temporarily created pseudo reference via the "post-receive
" hook, having a temporary reference is not safe for concurrent pushes.
So, add a filter and a new handler to support this kind of workflow.
The filter will check the prefix of the reference name, and if the command has a special reference name, the filter will turn a specific field (run_proc_receive
) on for the command.
Commands with this filed turned on will be executed by a new handler (a hook named "proc-receive
") instead of the internal execute_commands
function.
We can use this "proc-receive
" command to create pull requests or send emails for code review.
After receiving a command, the hook will execute the command, and may create/update different reference.
For example, a command for a pseudo reference "refs/for/master/topic
" may create/update different reference such as "refs/pull/123/head
".
The alternate reference name and other status are given in option lines.
这对于 Git 2.30(2021 年第一季度)更加稳健:receive-pack
和 proc-receive
挂钩之间的交换没有仔细检查错误。
见commit 80ffeb9, commit f65003b, commit cf3d868 (11 Nov 2020) by Jiang Xin (jiangxin
)。
(由 Junio C Hamano -- gitster
-- in commit 8f8f10a 合并,2020 年 11 月 25 日)
receive-pack
: gently write messages to proc-receive
Reported-by: Johannes Schindelin
Suggested-by: Jeff King
Signed-off-by: Jiang Xin
Johannes found a flaky hang in t5411/test-0013-bad-protocol.sh
in the osx-clang job of the CI/PR builds, and ran into an issue when using the --stress
option with the following error messages:
fatal: unable to write flush packet: Broken pipe
send-pack: unexpected disconnect while reading sideband packet
fatal: the remote end hung up unexpectedly
In this test case, the "proc-receive" hook sends an error message and dies earlier.
While "receive-pack" on the other side of the pipe should forward the error message of the "proc-receive" hook to the client side, but it fails to do so.
This is because "receive-pack" uses packet_write_fmt()
and packet_flush()
to write pkt-line message to "proc-receive" hook, and these functions die immediately when pipe is broken.
Using "gently" forms for these functions will get more predicable output.
Add more "--die-*
" options to test helper to test different stages of the protocol between "receive-pack
" and "proc-receive
" hook.
我在此处查看文档:https://git-scm.com/docs/git-request-pull
但我不确定如何将它应用到我想做的事情上。我推送到名为 "fix/fixNumberHere" 的分支,我想使用拉取请求合并到名为 "mergeBranch" 的分支——如何将其应用于:
git request-pull [-p] <start> <url> [<end>]
我想你会使用这个语法:
git request-pull mergeBranch origin fix/fixNumberHere
^^^ start ^^ url ^^^ end
我认为大多数 Git 用户通常会直接在远程创建拉取请求,例如如果他们使用 GitHub 或 BitBucket 之类的东西。
根据远程存储库,git request-pull
不再是唯一的选择:借助 Git 2.29(2020 年第 4 季度)的新 server-side 挂钩,可以自动创建 PR :
"git receive-pack
"(man) 接受“git push
”的请求学会了将大部分 ref 更新外包给 新的“proc-receive
" 挂钩.
参见 commit d6edc18, commit 1702ae6, commit c6a6a01, commit 31e8595, commit b913075, commit 63518a5, commit 195d6ea, commit 15d3af5, commit 38b9197, commit 917c612 (27 Aug 2020) by Jiang Xin (jiangxin
)。
(由 Junio C Hamano -- gitster
-- in commit 6c430a6 合并,2020 年 9 月 25 日)
receive-pack
: add newproc-receive
hookSigned-off-by: Jiang Xin
Git calls an internal
execute_commands
function to handle commands sent from client togit-receive-pack
.Regardless of what references the user pushes, Git creates or updates the corresponding references if the user has write-permission.
A contributor who has no write-permission, cannot push to the repository directly.
So, the contributor has to write commits to an alternate location, and sends pull request by emails or by other ways.
We call this workflow as a distributed workflow.It would be more convenient to work in a centralized workflow like what Gerrit provided for some cases.
For example, a read-only user who cannot push to a branch directly can run the following
git push
(man) command to push commits to a pseudo reference (has a prefix "refs/for/
", not "refs/heads/
") to create a code review.git push origin \ HEAD:refs/for/<branch-name>/<session>
The
<branch-name>
in the above example can be as simple as "master
", or a more complicated branch name like "foo/bar
".
The<session>
in the above example command can be the local branch name of the client side, such as "my/topic
".We cannot implement a centralized workflow elegantly by using "
pre-receive
" + "post-receive
", because Git will call the internal function "execute_commands
" to create references (even the special pseudo reference) between these two hooks.
Even though we can delete the temporarily created pseudo reference via the "post-receive
" hook, having a temporary reference is not safe for concurrent pushes.So, add a filter and a new handler to support this kind of workflow.
The filter will check the prefix of the reference name, and if the command has a special reference name, the filter will turn a specific field (
run_proc_receive
) on for the command.
Commands with this filed turned on will be executed by a new handler (a hook named "proc-receive
") instead of the internalexecute_commands
function.We can use this "
proc-receive
" command to create pull requests or send emails for code review.After receiving a command, the hook will execute the command, and may create/update different reference.
For example, a command for a pseudo reference "
refs/for/master/topic
" may create/update different reference such as "refs/pull/123/head
".
The alternate reference name and other status are given in option lines.
这对于 Git 2.30(2021 年第一季度)更加稳健:receive-pack
和 proc-receive
挂钩之间的交换没有仔细检查错误。
见commit 80ffeb9, commit f65003b, commit cf3d868 (11 Nov 2020) by Jiang Xin (jiangxin
)。
(由 Junio C Hamano -- gitster
-- in commit 8f8f10a 合并,2020 年 11 月 25 日)
receive-pack
: gently write messages toproc-receive
Reported-by: Johannes Schindelin
Suggested-by: Jeff King
Signed-off-by: Jiang Xin
Johannes found a flaky hang in
t5411/test-0013-bad-protocol.sh
in the osx-clang job of the CI/PR builds, and ran into an issue when using the--stress
option with the following error messages:fatal: unable to write flush packet: Broken pipe send-pack: unexpected disconnect while reading sideband packet fatal: the remote end hung up unexpectedly
In this test case, the "proc-receive" hook sends an error message and dies earlier.
While "receive-pack" on the other side of the pipe should forward the error message of the "proc-receive" hook to the client side, but it fails to do so.
This is because "receive-pack" usespacket_write_fmt()
andpacket_flush()
to write pkt-line message to "proc-receive" hook, and these functions die immediately when pipe is broken.Using "gently" forms for these functions will get more predicable output.
Add more "
--die-*
" options to test helper to test different stages of the protocol between "receive-pack
" and "proc-receive
" hook.