git 在拉取请求时重命名分支
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/20007578/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Renaming a branch while on pull request
提问by Michele
On Github, you can make pull requests to add functionality to a project. One's contributions have to be on a branch that, if the request is accepted, will be merged into the master branch (or an analogous one) of the project.
在 Github 上,您可以发出拉取请求以向项目添加功能。一个人的贡献必须在一个分支上,如果请求被接受,它将被合并到项目的主分支(或类似的分支)中。
Now, I submitted a pull request on Github and my contributions are on a branch called patch-1
. I can modify the name of the branch locally by
现在,我在 Github 上提交了一个拉取请求,我的贡献在一个名为patch-1
. 我可以通过以下方式在本地修改分支的名称
git branch -m patch-1 newname
and in principle I can also rename it on my forked repo on Github by following the instruction found in this answer. This is done in practice by removing the old branch, patch-1
in my case, and repush it with a different name newname
.
原则上,我也可以按照此答案中的说明在 Github 上的分叉存储库中重命名它。这在实践中是通过删除旧分支来完成的,patch-1
在我的情况下,并用不同的名称重新推送它newname
。
Is it allowed to rename the branch patch-1
on my forked repository on Github when it constitutes a pull request?
Or it causes problems on the pull request management?
patch-1
当它构成拉取请求时,是否允许重命名我在 Github 上的分叉存储库中的分支?或者它会导致拉取请求管理出现问题?
Is there any way to rename a branch on a forked repository on Github when that branch is a pull request?
当该分支是拉取请求时,有没有办法重命名 Github 上分叉存储库上的分支?
回答by arbylee
"Renaming" a remote branch in git, as indicated by the link you provided, is really just deleting a branch, followed by pushing a new one with the same commit hash but a new name. If you have a pull request open for branch patch-1, when you delete that branch, the pull request will be closed.
正如您提供的链接所示,在 git 中“重命名”远程分支实际上只是删除一个分支,然后推送一个具有相同提交哈希但具有新名称的新分支。如果您为分支 patch-1 打开了拉取请求,则当您删除该分支时,拉取请求将被关闭。
So, no you can't rename the branch with a pull request open without deleting the branch and removing the pull request. However, there's nothing stopping you from doing that, pushing a new branch with a new name, and creating a new pull request.
因此,不,您不能在不删除分支并删除拉取请求的情况下在拉取请求打开的情况下重命名分支。但是,没有什么可以阻止您这样做,使用新名称推送一个新分支,并创建一个新的拉取请求。
回答by Slobodan Ilic
Short answer:
简短的回答:
No
不
Alternative approach:
替代方法:
- Open a new PR with a new (renamed) branch
- Close the old PR referencing the new one (e.g. Closed in favor of #new_pr_id)
- Modify the description of the new PR (e.g. Supersedes #old_pr_id)
- (optional) Make a comment about relevant discussion on the old PR
- 用一个新的(重命名的)分支打开一个新的 PR
- 关闭引用新 PR 的旧 PR(例如已关闭以支持 #new_pr_id)
- 修改新 PR 的描述(例如 Supersedes #old_pr_id)
- (可选)对旧 PR 的相关讨论发表评论
Note:
笔记:
The name of a remote branch (constituting a PR) needed to change, because the build system needed the branch's name that ends with the ticket ID. However, the PR was opened prior to official ticket creation (from specs), and had contained valuable discussion. The described approach was the only way to make build system work, and also not lose any information (although there was an extra step in tracking it).
远程分支(构成 PR)的名称需要更改,因为构建系统需要以票证 ID 结尾的分支名称。但是,PR 是在官方门票创建之前(根据规范)打开的,并且包含了有价值的讨论。所描述的方法是使构建系统工作的唯一方法,并且不会丢失任何信息(尽管跟踪它有一个额外的步骤)。