我一直在寻找一种方法来自动更新项目的主分支(已发布版本)的过程。
基本上只有两个分支将存在于原始存储库中(开发和掌握...当修补程序或特定的开发分支出现时可能更多)。
然而,在修复nvie文章(http://nvie.com/posts/a-successful-git-branching-model/)中的所有命令时,在向多个潜在维护者进行养殖时容易出错。
为了缓解版本命名约定中可能存在拼写错误的问题,并使所有维护者的流程保持一致和可靠,我想编写一个脚本来验证输入。
答案 0 :(得分: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
答案 1 :(得分:1)
我认为你正在寻找这个: https://github.com/nvie/gitflow
这是一组脚本,可以处理git流模型所需的所有内容。