繁体   English   中英

Git / bash更新本地分支

[英]Git/bash Updating local branches

我正在编写一个小的bash脚本,如下所示:

#if you add a project you must use the format git clone https://<username>:<passsord>@github.com/ZiathLtd/<project-name>.git
#projects[1]=samples
#projects[2]=TubePicker
#projects[3]=FloydDriver
#projects[4]=Handheld
projects[1]=handheldserver
#projects[6]=ziathscripts
#projects[7]=handheldscripts

basedir="/mnt/raid/git"

for i in ${projects[@]}; do
        echo 'updating' ${i}
        cd ${basedir}/${i}

        for b in `git branch -r | grep -v -- '->'`; do
                echo working on ${b}

                git rev-parse --verify ${b}
                if [ $? -ne 0 ]
                        then
                                echo 'new branch'
                                git branch --track ${b##origin/} $b;
                fi
        done
        #git fetch --all
        #git pull --all
done

基本上,它应该给我没有本地分支机构的项目。 但是,当我执行此脚本时(分支fake-news2不在远程仅本地存在),我得到以下信息:

root@alfred:/etc/git-fetch# ./git-fetch.sh
updating handheldserver
working on origin/converttospringbootproject
5eee6f6d65feb2f49f4f7a4edecc37a17081dfae
working on origin/fake-news
95e840807a2c7d125c053a6a06bb1e9c7fd11b78
working on origin/fake-news2
95e840807a2c7d125c053a6a06bb1e9c7fd11b78
working on origin/fake-news3
497ecdc1e31f312884fe9666ef3408f3bd8083c8
working on origin/master
1a541521941687ae27bccfa412c4372db9afeaea
working on origin/maven-spring-boot-plugin
46e25767e41a639c6cc7760fe4a2249d01a00060

请注意,fake-news2的哈希值与false-news相同-就像对fake-news2的调用使用了fake-news标签一样(我希望您喜欢我在虚拟分支中使用的讽刺名称! )。 但是,在命令行上运行时,我得到以下信息:

root@alfred:/mnt/raid/git/handheldserver# git rev-parse --verify fake-news
95e840807a2c7d125c053a6a06bb1e9c7fd11b78
root@alfred:/mnt/raid/git/handheldserver# echo $?
0
root@alfred:/mnt/raid/git/handheldserver# git rev-parse --verify fake-news2
fatal: Needed a single revision
root@alfred:/mnt/raid/git/handheldserver# echo $?
128

这是您期望的,因为fake-news2没有本地分支。 看起来git在循环中做一些奇怪的事情,或者我正在运行的命令在echo上获得了$ {b}的正确变量,但在命令上却没有。

我完全被困住了,所以我希望有人来过这里。 请注意,我尝试了其他git命令来检查本地分支(例如show-ref)的存在,但它们似乎都在做相同的事情。

在此先感谢您的帮助

如果本地不存在fake-news2,为什么还要期望这两个命令具有相同的结果?

git rev-parse --verify fake-news2 #The one you used on the command-line
git rev-parse --verify origin/fake-news2 #The one you used in your script

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM