我有一个Bash脚本,接受一个字符串,可以是分支名称(例如“master”或“feature/foo”)或提交哈希(例如“1234abcd”)。
我已经检出了存储库,所以可以调用git。
最好的方法是确定该字符串是分支名称还是提交哈希?
#!/bin/bash
commit_or_branch="$1"
cd /path/to/my_repo
git fetch
if <is_branch $commit_or_branch>
then
echo "it's a branch"
else
echo "it's a commit"
fi
git pull
,而提交则不需要。如果它是一个提交,我可能想检查它属于哪些分支。还有其他许多事情。 - k107