我如何重命名尚未被推到远程仓库的本地分支 ?
相关:
当前回答
高级 Git 用户可以手动重命名 :
Rename the old branch under .git/refs/heads to the new name
Rename the old branch under .git/logs/refs/heads to the new name
Update the .git/HEAD to point to yout new branch name
其他回答
重命名当前分支 :
git branch -m <newname>
将指定给任何分支的分支重新命名 :
git branch -m <oldname> <newname>
-m
短为--move
.
推动地方分支并重设上游分支:
git push origin -u <newname>
删除远程分支 :
git push origin --delete <oldname>
创建git rename
别名 :
git config --global alias.rename 'branch -m'
在 Windows 或其他不区分大小写的文件系统上使用-M
如果名称仅出现资本化变化, 则该名称只有资本化变化 。 否则, Git 将投"部门已经存在"错误 。
git branch -M <newname>
所有你必须做的是三步:
.git/refs/heads
新名称.git/logs/refs/heads
新名称.git/HEAD
导致您新分支名称我愚蠢地命名了一个树枝 从连字符开始, 然后检查了主人。删除删除我的分支,我有工作在里面。
这两种办法都行不通:
git checkout -dumb-name
git checkout -- -dumb-name
"
s,'
s 和 s , s 和 s\
也没有帮助。git branch -m
没有工作。
我终于把它修好了。 进入您的工作副本 . git/ refs/ heads, 找到文件名“ - dumb- name ” , 获取分支的大麻。 然后, 这将检查它, 制造一个新的有正常名称的分支, 并删除旧的分支 。
git checkout {hash}
git checkout -b brilliant-name
git branch -d -- -dumb-name
高级 Git 用户可以手动重命名 :
Rename the old branch under .git/refs/heads to the new name
Rename the old branch under .git/logs/refs/heads to the new name
Update the .git/HEAD to point to yout new branch name
更新2023年最新情况
在开始之前, 请确定您已经选择了您想要重命名的分支 :
git checkout old-name
如果您想要看到本地所有的分支,请使用以下命令:
git branch --list
当你们清清楚楚时,
使用 Git 重命名分支命令需要添加- 中 - 中命令的选项 :
git branch -m new-name
您也可以使用以下两个命令从另一个分支重命名本地分支 :
git checkout master
git branch -m old-name new-name
最后,该指挥部将列出所有(地方和偏远地区)分支,以核实其是否已重新命名:
git branch -a
虽然无法直接重命名一个远程分支, 但重命名一个分支的过程包括两个简单步骤:
要开始, 您需要按照前几个步骤重命名本地分支 。 2. 然后再重命名本地分支 。删除删除排旧分支和分支推进排新建新。您可以通过下列命令轻而易举地做到这一点:
git push origin :old-name new-name
重新设置您新的本地分支的上游分支, 您将全部设置 :
git push origin -u new-name