我想在那里得到这个问题,看看我是否做得对.以下脚本工作,除了检查提交是否已被推送到远程仓库,我找不到正确的命令:
#!/bin/bash
set -e # fail on first error
verify_git_ref() {
log "Verifying git tag or commit: \"$1\" ...."
if git show-ref --tags --quiet --verify -- "refs/tags/$1"
then
log_success "Git tag \"$1\" verified...."
GIT_TAG_OR_REF=$1
return 0
elif git rev-list $1>/dev/null 2>&1
then
log_success "Git commit \"$1\" verified...."
GIT_TAG_OR_REF=$1
return 0
else
log_error "\"$1\" is not a valid tag or commit, you must use a valid tag or commit in order for this script to continue"
return 1
fi …Run Code Online (Sandbox Code Playgroud) 我是一个患有先前svn经验的git新手.我的很多项目都使用自己库中的代码,所以很自然地我想从git中获得一些"类似于外部"的功能.我目前正在尝试使用子模块.
但是如果以错误的方式使用子模块(据我所知),子模块可能会带来很大的痛苦(例如,更改子模块中的文件并忘记推送它们,或者忘记提交它们).
如果我将子模块中的所有文件设为只读怎么办?这足以防止意外更改.如果我真的想改变一些东西,我应该去改变原来的回购.
所以,我的问题是:
编辑:我希望可以通过git hook实现,但我不确定如何.我第一次克隆回购时不能使用客户端挂钩,是吗?
EDIT2:在SRobertz的帮助下,我能够拿出一个结账后的钩子:
echo "you just checked out: $*"
echo "submodules:"
for p in `grep path .gitmodules | sed 's/.*= //'`; do # get submodules list
echo "making submodule directory $p read-only"
chmod -R a-w $p;
SAVEIFS=$IFS
IFS=$(echo -en "\n\b") #set delimeter to \n\b to handle whitespaces in filenames
for f in `ls $p`; do #get files in submodule dir
echo "making file $f in directory $p read-only"
chmod -R a-w $p\\$f;
done
IFS=$SAVEIFS …Run Code Online (Sandbox Code Playgroud)