我如何重命名尚未被推到远程仓库的本地分支 ?
相关:
当前回答
我愚蠢地命名了一个树枝 从连字符开始, 然后检查了主人。删除删除我的分支,我有工作在里面。
这两种办法都行不通:
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 branch -m [old_branch_name] [new_branch_name]
-m
:它重命名/移动分支。如果已经有一个分支,则会出错。
如果已经有一个分支, 您想要用该分支重命名, 请使用 :
git rename -M [old_branch_name] [new_branch_name]
有关帮助的更多信息,请在终端中使用此命令 :
git branch --help
或
man git branch
我愚蠢地命名了一个树枝 从连字符开始, 然后检查了主人。删除删除我的分支,我有工作在里面。
这两种办法都行不通:
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 branch -m
。 当然, 操作很容易, 但对我来说, 可能很难记住另一个 Git 命令 。 所以我试图完成我熟悉的指令。 是的, 你可能猜到了 。
我用的是git branch -b <new_branch_name>
。如果你不想保存旧的分支,现在你可以执行git branch -D <old_branch_name>
要删除它。
我知道这或许有点无聊, 但更容易理解和记住。我希望这对你有益。
有关这一程序的更多详情。
git checkout oldbranch
git branch -m newbranch
git branch -m oldbranch newbranch
如果其他用户使用此分支并承诺执行此分支, 您应该在将其重新命名为本地之前将其拉动 。 这样可以确保您的本地仓库得到更新, 并确保其他用户所做的更改不会丢失 。
首先,我们需要删除oldbranch
从远程仓库中键,然后按enwbranch
至远程。
git push origin --delete oldbranch
使用-u(固定上游)选项,
git push origin -u newbranch
如果是您的当前分支, 只需做
git branch -m new_name
如果它是另一个分支, 您想要重命名
git branch -m old_name new_name
- 如果您的分支被推动, 那么在重新命名后, 您需要从远程 Git 仓库删除它, 并要求您的新本地端跟踪新的远程分支 :
git push origin :old_name
git push --set-upstream origin new_name