一个接一个地单独推送一个分支的所有提交

krl*_*mlr 5 git push git-push githooks

有没有一种简单的方法可以逐一推送功能分支(例如,从 开始master)的所有提交,以便每次提交都会触发远程端的推送挂钩?当您首先实施并提交失败的测试,然后进行修复时,这对于“测试优先”场景非常有用。

我知道我可以做git push sha:remote-ref-name,但手动做很乏味。

cfo*_*ish 3

这个脚本应该可以工作:

#!/bin/bash

if [ ! -d .git ]; then
    echo "$(basename $0): not a git directory." 1>&2
    exit 1
fi

# lbranch - name of local branch
# remote  - name of remote
# rbranch - name of remote branch
lbranch=$(git rev-parse --abbrev-ref HEAD)
remote=$(git config branch.${lbranch}.remote)
rbranch=$(git config branch.${lbranch}.merge)
rbranch=${rbranch/refs\/heads\//}

for rev in $(git rev-list --reverse ${lbranch} --not --remotes);
do
    git push ${remote} ${rev}:${rbranch}
done
Run Code Online (Sandbox Code Playgroud)