重命名Git分支文件夹 [英] Rename Git branch folder

查看:156
本文介绍了重命名Git分支文件夹的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

  bugfix001 
bugfix002
feature
feature001
feature002
feature003
master
任务
task001
task002


其中'feature'和'task'是分支结构内的文件夹,'feature001','feature002'分支位于父'特征'分支文件夹下。 / p>

我的问题是 - 是否可以重命名功能父文件夹并将所有分支保留在它下面。所以我可以将它重命名为'仓鼠',结构看起来像这样

 仓鼠
feature001
feature002
feature003

要说清楚,我并不是指本地文件结构,这是遥控器上的分支结构。要在'feature'文件夹下添加一个分支,我会使用:

  git checkout -b feature / feature004 

我意识到我可以单独重命名每个子分支并将其推送到远程,但是我可以重命名'feature'父文件夹会导致子分支遵循新名称吗?

解决方案

在git中没有分支文件夹这样的东西。 / p>

您只有命名分支,并且您使用的名称恰好包含一个斜杠,用于提醒人们文件夹结构;但它确实可能是其他的东西(例如 @ )。



结束语:您将不得不重新命名每一个分支,并推新的分支名称(并删除旧分支)



但应该很简单:

  remote = origin 
用于分支$(git branch --listfeature / *)
do
newbranch =hamster / $ {branch#feature /}
#在本地创建基于旧分支的新分支
git checkout$ {branch}
git checkout -b$ {newbranch}
#将新分支推送到远程
git push --set-upstream$ {remote}$ {newbranch}
#远程和本地删除旧分支
git push$ {remote}:$ {branch}
git branch -d$ {branch}
完成


I have a Git repository with a remote branch structure like this:

bugfix001 
bugfix002     
feature
    feature001
    feature002
    feature003
master
task
    task001
    task002

where 'feature' and 'task' are folders within the branch structure and the 'feature001', 'feature002' branches are under the parent 'feature' branch folder.

My question is - is it possible to rename the 'feature' parent folder and keep all the branches under it. So I could rename it to 'hamster' and the structure would look like this

hamster
    feature001
    feature002
    feature003

Just to be clear, I'm not referring to the local file structure, this is the branch structure on the remote. To add a branch under the 'feature' folder I would use:

git checkout -b feature/feature004

I realise that I can rename each sub branch individually and push to the remote but can I rename the 'feature' parent folder which will cause will the sub branches follow the new name?

解决方案

There is no such thing as "branch folders" in git.

You only have named branches, and the names you are using happen to include a slash, which reminds the humans of a folder-structure; but it really could be something else as well (e.g. @).

To conclude: you will have to rename every branch, and push the new branch names (and delete the old ones)

But that should be simple enough:

remote=origin
for branch in $(git branch --list "feature/*")
do
 newbranch="hamster/${branch#feature/}"
 # locally create new branch based on old one
 git checkout "${branch}"
 git checkout -b "${newbranch}"
 # push the new branch to the remote
 git push --set-upstream "${remote}" "${newbranch}"
 # delete old branch remotely and locally
 git push "${remote}" ":${branch}"
 git branch -d "${branch}"
done

这篇关于重命名Git分支文件夹的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆