2

我正在寻找一种方法来自动化更新项目的主分支(发布版本)的过程。

基本上只有两个分支将存在于原始存储库中(开发和主......当修补程序或特定开发分支出现时可能更多)。

然而,运行 nvie 文章 (http://nvie.com/posts/a-successful-git-branching-model/) 中的所有命令在外包给多个潜在维护者时容易出错。

为了减轻版本命名约定中可能出现的拼写错误问题,并使所有维护者的过程一致和可靠,我想编写一个脚本来验证输入。

4

2 回答 2

5

这是我bump.sh调用的脚本,我给它一个新版本来更新。它负责处理其余过程的大部分。

me@server:~/git_repos/# ./bump.sh git_project

Enter new version (Current 1.0.5): 1.0.6
Are you sure you want to release version 1.0.6? (y|n): y
Switched to a new branch 'release-1.0.6'
Switched to branch 'master'
Deleted branch release-1.0.6 (was 4abcd98e).

If you need to undo this last commit, abort now and run:
  git reset --hard HEAD~1
  git tag -d 1.0.6

Do you want to push this to the origin server (THIS IS NOT EASILY UNDONE)? (y|n): y
Password for 'https://user@bitbucket.org':
Counting objects: 7, done.
Delta compression using up to 8 threads.
Compressing objects: 100% (5/5), done.
Writing objects: 100% (5/5), 704 bytes, done.
Total 5 (delta 2), reused 0 (delta 0)
remote: bb/acl: user is allowed. accepted payload.
To https://remote_repository.../.git
   ffffffab..010101ab  master -> master
Finished merging.

bump.sh

if [ ! -d "$1" ]; then
    echo "Must pass git directory as the first argument."
    exit 2;
fi

cd $1
echo -e "Enter new version (Current `git describe --abbrev=0 --tags`): \c "
while read ver; do
    if ([[ ! -z "$ver" ]]) && ([ "$ver" == "`echo $ver | grep "^[0-9]\{1,\}\.[0-9]\{1,\}\.[0-9]\{1,\}$"`" ])
    then
        break
    else
        echo "  Version entered ($ver) was not formatted properly."
        echo -e "Enter new version (Current `git describe --abbrev=0 --tags`): \c "
    fi
done

echo -e "Are you sure you want to release version $ver? (y|n): \c "
read confirm

if([ $confirm == "y" ]) then
    git checkout -b release-$ver develop
    git checkout master
    result=`git merge --no-ff release-$ver`
    if([ "$result" == "`echo $result | grep "^Already up-to-date\."`" ]) then
        git branch -D release-$ver
        echo "The branch is already up to date.  Aborting version bump.";
        exit 3;
    else
        git tag -a $ver -m "Used bump script."
        git branch -D release-$ver
        echo ""
        echo "If you need to undo this last commit, abort now and run:"
        echo "  git reset --hard HEAD~1"
        echo "  git tag -d $ver"
        echo ""
        echo -e "Push this change to the origin server and merge back into the develop branch? (y|n): \c "
        read confirm 
        if([ $confirm == "y" ]) then
            git push origin master
            git checkout develop
            git merge master
        fi

        echo "Finished merging."
        exit 1;
    fi
else
    echo "Aborted the version bump."
    exit 1;
fi
于 2012-11-29T01:28:10.480 回答
1

我想你正在寻找这个: https ://github.com/nvie/gitflow

那是一组脚本,可以处理 git 流模型所需的所有内容。

于 2012-11-29T01:44:40.677 回答