git - 是否有一段代码可以防止更改合并/推送到 git?
问题描述
如果我需要一些额外的代码来在我的本地服务器上运行某些东西,但需要记住在推送到 git 或合并到受保护的分支之前将其删除。
如果我忘记删除该代码,是否有一段代码(或 vscode 扩展)可以通知 git 或在推送时通知我。喜欢//TODO:
或git可以识别的东西?
解决方案
在 git 方面:您可以在本地 repo 中添加一个 pre-push 钩子来扫描代码中的禁用词,如果找到该词则取消推送。
例如,这是一些寻找的代码dontpush
(它使用git grep -i
,任何大小写"DoNtPuSh"
都可以)并且如果在您的本地提交中找到它就不会推送:
# file '.git/hooks/pre-push' :
#!/bin/bash
remote="$1"
url="$2"
z40=0000000000000000000000000000000000000000
while read local_ref local_sha remote_ref remote_sha
do
if [ "$local_sha" = $z40 ]
then
# Delete: nothing to do on deleted branches
else
# Check if "dontpush" appears in the local commit :
dontpush=`git grep -n -i dontpush $local_sha -- $files`
if [ -n "$dontpush" ]
then
# print 'git grep' output on STDERR,
# remove the leading "sha:" on each line
(echo $dontpush | sed -e 's/^[^:]*://') | cat >&2
echo >&2 "*** Found 'dontpush' tag in $local_ref, not pushing"
exit 1
fi
fi
done
exit 0
推荐阅读
- javascript - 如何使用 javascript 赋予标准或用户价值
- python - 如何在熊猫数据框中列出唯一组合
- python - 随机森林特征重要性的交叉验证数据集折叠
- javascript - 如何允许用户在我的网站上使用 Gmail 登录
- php - ZendFramework 2 - 我的班级中的 ServiceManager
- ruby-on-rails - 使用对活动存储导轨的反应上传图像
- intellisense - VBE 中的 Intellisense 不能对对象完全起作用
- java - camel-http4 2.22 - toD 不工作
- r - 从R中的坐标分组中保存线的快速方法
- javascript - Javascript,存储一个数字并在另一个 html 页面上检索