在git flow中重命名一个分支

25

使用git-flow,是否可以重命名一个特性分支?

我尝试查找git flow helpgit flow feature help,还有git-flow cheatsheet,但没有找到任何信息。

或者,直接使用git branch -m feature/new_name是否安全?


查看此链接 https://dev59.com/9UfRa4cB1Zd3GeqP6BE- - Vaibhav Mule
3个回答

46

没错。

你可以这样做,但如果你推送了分支并且有人正在使用它,你需要告诉他们更新更改。

gitflow 分支与其他分支没有区别。

重命名本地分支

Git初学者(普通方式)

#Checkout new branch and delete the old one
git checkout -b <new_name>
git branch -D <old_name>

#Use the short git branch move (-m flag)
git branch -m <old_name> <new_name>

#Use the long git branch move (–move flag)
git branch --move <old_name> <new_name>

高级技巧:手动重命名分支

(不推荐——也就是说,不要在家里尝试!!!)

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 your new branch name.

Sit back and Enjoy GIT :-)

为了真正理解事物,我还需要了解git-flow是什么以及它的作用。特别是,git-flow是否在任何地方存储自己的信息。 - Andrew Grimm
没错,除非你对git的工作原理感兴趣,否则没有必要了解幕后发生的事情。对于你的问题,简单的答案是可以将分支重命名,但如果你的开发团队已经从主服务器上拉取了该分支,则需要更新他们已更名的分支。 - CodeWizard

16

您可以使用git-flow feature rename NewFeatureName来重命名一个功能。

这似乎没有很好的文档记录。您可以在这里找到参考资料。


1
看起来不错,尽管它不支持重命名发布分支。 - negrotico19

9

是的,但如果您使用gitflow,您还需要手动修改(我不知道是否有自动方式)文件.git/config,并将git-flow功能名称重命名为要重命名的功能。


在 .git/config 中没有实际功能名称。只有那些功能在其分支名称中具有 feature/... 的特征。 - pashute

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接