»
(008)CubeIDE实现USB外设*
(018)C99 的指针*
(019)C99 只有值赋值,没有move*
(022)POSIX线程库pthread的同步锁*
(023)POSIX线程库pthread的多线程*
(027)C99标准库中的计时与等待 *
(028)C语言中的高精度计算库GMP *
(029)C语言中的Web服务*
(030)C语言中的字符转码ICU*
(031)从几个方面显然C语言比C++效率高*
🍓(014)Git禁止reset --hard
Git禁止reset --hard
cd /path/to/repo.git/hooks
touch pre-receive
chmod +x pre-receive
#!/bin/bash
#oldrev是服务器(远程仓库)中当前的分支的当前提交哈希
#newrev是推送者希望远程更新到仓库中去的提交哈希
# 读取标准输入,获取引用更新信息
while read old_ref new_ref ref_name; do
echo "Received push:"
echo "Old ref: $old_ref"
echo "New ref: $new_ref"
echo "Ref name: $ref_name"
# 检查是否是为第一次推送(oldrev 为 0000000000000000000000000000000000000000)
if [ "$old_ref" = "0000000000000000000000000000000000000000" ]; then
echo "Allow first push: $refname"
exit 0
fi
# 检查是否是删除分支(oldrev 存在,但 newrev 为 0000000000000000000000000000000000000000)
if [ "$new_ref" = "0000000000000000000000000000000000000000" ]; then
echo "ERROR: Deleting branches is not allowed."
exit 1
fi
# 检查是否是强制推送(newrev 存在但 oldrev 不是它的祖先)
if ! git merge-base --is-ancestor "$old_ref" "$new_ref"; then
echo "force push is not allowed: $refname"
exit 1
fi
# 检查是否包含 reset 操作
if [[ "$old_ref" != "0000000000000000000000000000000000000000" && "$new_ref" != "0000000000000000000000000000000000000000" ]]; then
commits=$(git rev-list $old_ref..$new_ref)
for commit in $commits; do
if git log -1 --pretty=%B $commit | grep -q "git reset"; then
echo "ERROR: Push contains 'git reset' operation in commit $commit."
exit 1
fi
done
fi
done
# 如果未检测到不允许的情况,则允许推送
exit 0
来自:DeepSeek综合ChatGPT