2017-06-15 60 views
0

我知道我可以重命名一个分支如何重命名分支的家庭/模式一步到位

git branch -m new-branch-name 

而且也是我可以从另一个分支重新命名分支:

git branch -m old-branch-name new-branch-name 

但我想知道如果我可以重新命名一系列分支替换所有这些分支的路径。例如

foo/bar/1.2 
foo/baracca/1.2 
foo/baratro/1.2 
foo/barbabietola/1.2 
foo/bartender/1.2 

应该在改变

foo/bar/1.3 
foo/baracca/1.3 
foo/baratro/1.3 
foo/barbabietola/1.3 
foo/bartender/1.3 

“在1.3替换1.2” 或 “与我foo换成”

meh/bar/1.2 
meh/baracca/1.2 
meh/baratro/1.2 
meh/barbabietola/1.2 
meh/bartender/1.2 

回答

1

我会做这样的:

git branch | grep 1.2 | while read branch; do 
    new_branch=$(echo $branch | sed 's/1.2/1.3/') 
    echo moving $branch to $new_branch 

    # enable next line when we are sure the name of the branches is correct 
    # git branch -m $branch $new_branch 
done 
+0

我试图用同一条线做同样的事情 – sensorario

+0

1-liner是添加相同的东西;每行:'''git branch | grep 1.2 |同时阅读分支;做new_branch = $(echo $ branch | sed's/1.2/1.3 /');回声移动$分支到$ new_branch; git分支-m $分支$ new_branch; done''' – eftshift0