2017-06-15 66 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