git别名;git配置使用shell函数;git别名使用shell函数;git获取当前分支;git alias
- 获取当前分支
git symbolic-ref -q --short HEAD
2. 在git别名里使用shell函数,$1获取第一个参数的值,$2……$n依次类推,根据自己习惯需要定制
3. 提交review的正确语句是: git push origin HEAD:refs/for/destination_branch 意思是---把当前分支的代码推送到远程origin仓库的review分支destination_branch上去
origin表示远程git服务器地址;HEAD表示当前分支;refs/for/destination_branch 表示远程review分支
4. 下面配置的含义:
- 执行git review等价于git push origin HEAD:refs/for/current_branch
- 执行git review destination_branch等价于git push origin HEAD:refs/for/destination_branch
review = "!f() { if [ -z $1 ];then currBra=`git symbolic-ref -q --short HEAD`;else currBra=$1;fi;git push origin HEAD:refs/for/$currBra; }; f" |
全部配置:
[core] repositoryformatversion = 0 filemode = true bare = false logallrefupdates = true ignorecase = true precomposeunicode = true [remote "origin" ] url = ssh: //san.zhang@gerrit.xxx.me:29418/ganhui.zhang/gerrit_test fetch = +refs/heads/*:refs/remotes/origin/* [branch "master" ] remote = origin merge = refs/heads/master [branch "gerrit_test1811052223a" ] remote = origin merge = refs/heads/gerrit_test1811052223 [branch "gerrit_test1811052223" ] remote = origin merge = refs/heads/gerrit_test1811052223 [alias] st = status review = "!f() { if [ -z $1 ];then currBra=`git symbolic-ref -q --short HEAD`;else currBra=$1;fi;git push origin HEAD:refs/for/$currBra; }; f" |
配置生效的地方,优先级由高到底:
- 项目配置,位于项目下的.git/config 查看git config --local --list编辑git config --local -e
- 某个用户下的所有项目配置:~/.gitconfig 查看git config --global --list编辑git config --global -e
- 当前系统下的所有用户所有项目配置:/etc/gitconfig 查看git config --system --list编辑git config --system -e
注意:
配置的时候请使用命令:git config --local/--global/--system -e方式;
不要使用 git config --local/--global/--system alias.review "!f() { if [ -z $1 ];then currBra=`git symbolic-ref -q --short HEAD`;else currBra=$1;fi;git push origin HEAD:refs/for/$currBra; }; f"