将提交推送到另一个用户已打开拉取请求的分支

3

我有一个在Github上的代码库。这个代码库被另一个用户fork了。现在他已经发起了一个pull request。我想从我的端口推送一个提交到他的特性分支(他为此发起了PR),这是否可能呢?

下面是我所做的:

git pull remote-ref-other-user feature-branch

完成此操作后,我可以拉取他的提交。但是当我进行一些更改、添加其他提交并尝试以此方式推送时。

git push remote-ref-other-user feature-branch

我收到了这个错误。
error: src refspec feature-branch does not match any.
error: failed to push some refs to 'https://github.com/other-user/repo'

“我是否可以将我的提交推送到他的分支中?如果可以,那么该如何操作呢?”

你总是可以向衍生仓库发出一个计数器 PR。 - Code-Apprentice
2个回答

3
假设您已经将他的存储库 "mysamplerepository" 添加为远程仓库: git remote add johnrepo https://github.com/john/mysamplerepository 并且您有一个名为 "tweaks" 的分支。
如果您想将更改推送到他的存储库中名为 "master" 的分支,您应该执行以下操作: git push <remote-name> <source-ref>:<target-ref> 例如: git push johnrepo refs/heads/tweaks:refs/heads/master 请记住,您需要具有写入权限(推送访问权限)才能将更改推送到他的存储库。您可以在 Github 的文档 中了解更多信息。

谢谢@kopranb,它起作用了。git push <remote-name> <source-ref>:<target-ref>这个命令对我有用。+1 - BeginnersSake

1
如果可能的话,将取决于写入权限:
  • 作为存储库所有者,您应该有写入权限,以向另一个用户的PR添加提交(除非在用户的PR中明确关闭了此权限)
  • 如果您不是存储库所有者,则无法向另一个用户的PR添加额外的提交

在为GitHub用户添加远程后,例如:

git remote add <name of remote> git@github.com:<user>/<repo>.git

我使用


git checkout -b <name of branch> <name of remote>/<name of branch> 

创建一个本地分支来跟踪远程分支。当我进行更改并提交后,可以执行以下操作:

git push <name of remote> <name of branch>

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接