以下是我最后做的:
#!/bin/bash
# Find closest ancestor given two candidate branches
branch=`git rev-parse --abbrev-ref HEAD`
commit1=`git merge-base $branch ${1}`
commit2=`git merge-base $branch ${2}`
ancestor=`git merge-base ${commit1} ${commit2}`
if [[ "$commit1" == "$ancestor" ]]; then
echo ${2}
else
echo ${1}
fi
“我的要素”分支是从其中一个分支分支而来的
hotfix
develop
这些都是我给我父母的理由
git-branchestor.sh
脚本:
#!/bin/bash
remote="$1"
url="$2"
z40=0000000000000000000000000000000000000000
while read local_ref local_sha remote_ref remote_sha
do
if [ "$local_sha" = $z40 ]
then
# Handle delete
:
else
if [ "$remote_sha" = $z40 ]
then
# New branch, examine all commits
range="$local_sha"
else
# Update to existing branch, examine new commits
range="$remote_sha..$local_sha"
fi
branch=$(git rev-parse --abbrev-ref HEAD)
if [[ "$branch" != "hotfix" && "$branch" != "master" && "$branch" != "develop" ]]; then
ancestor=`~/bin/git-branchestor.sh hotfix develop`
echo "Open MR: https://gitlab.com/user/project/merge_requests/new?merge_request%5Bsource_branch%5D=${branch}&merge_request%5Btarget_branch%5D=${ancestor}"
echo ""
fi
fi
done
exit 0