【发布时间】:2020-02-01 05:00:05
【问题描述】:
我的本地分支映射到远程分支:
fetch = +refs/heads/release/old_branch:refs/remotes/origin/release/old_branch
我想将本地和远程old_branch 重命名为new_branch。 w3docs 推荐这个:
git branch -m old_branch new_branch # Rename branch locally
git push origin :old_branch # Delete the old branch
git push --set-upstream origin new_branch # Push the new branch, set local branch to track the new remote
但是,还有其他几个开发人员也在使用与我相同的远程 old_branch。上述建议在协作环境中是否安全?如果他们的.git/config 有类似于我上面的行,那么这个序列不会混淆他们的 fetch 引用吗?
【问题讨论】:
-
为什么不直接从旧分支创建新分支,将其公开,然后使用这个新分支?
-
@VelikiiNehochuha,有道理:如果有人继续使用 old_branch 并且分支出现分歧,我会将更改合并到 new_branch。谢谢,会的。
-
在删除旧的之前创建新的(通过
git push -u origin new_branch)。在某些情况下,这无关紧要。在其他情况下,它确实重要,它使“创建新”操作显着更有效率。您可能想知道何时(以及为什么)它更有效:答案是,如果删除旧名称会触发服务器端git gc抛出可从旧名称访问的提交,那么您随后创建新名称的推送必须重新发送git gc刚刚扔掉的所有提交。如果你先创建,所有的提交都会被保留。
标签: git git-branch