我如何重命名尚未被推到远程仓库的本地分支 ?
相关:
当前回答
一个简单的方法来做到这一点:
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
更多信息这笔.
其他回答
所有你必须做的是三步:
.git/refs/heads
新名称.git/logs/refs/heads
新名称.git/HEAD
导致您新分支名称以下是重新命名分支的步骤 :
git branch -m <new_name>
git push origin :<old_name>
git push origin <new_name>:refs/heads/<new_name>
EDIT(12/01/2017):确保您运行命令git status
并检查新创建的分支指向的是它自己的参考文献,而不是旧的参考文献。如果找到旧分支的引用文献,您需要解开上游的设置,使用 :
git branch --unset-upstream
要重命名当前分支( 除独立 HEAD 状态外) 您也可以使用此别名 :
[alias]
mvh = !sh -c 'git branch -m `git rev-parse --abbrev-ref HEAD` $1'
高级 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 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