如何防止对现有文件的更改,但允许在git reto中创建文件?
我假设服务器端的git挂钩至少是解决方案的一部分,但是我没有看到允许创建的方法,但 desok of toce of files 。
这里的用例是用于跟踪数据库模式更改的“迁移”脚本,因此文件将仅限于目录结构的特定部分中的特定类型。
I'm assuming a server-side git hook will be at least part of the solution, but I'm not seeing a way to allow creation but prevent modification of files.
The use-case here is "migration" scripts for tracking database schema changes, so the files will be limited to a particular type in a particular part of the directory structure.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
一种方法是简单地使用
git diff-index-cached Head
检查更改的类型。这将向您显示要更改哪些文件以及进行更改的类型:因此,您可以为更改类型字段解析此输出:
git git diff-index |切割-d''-f 5 |剪切-f 1
。这将为您提供所做更改类型的列表:您可以简单地检查任何修改或删除,并退出挂钩,如果对跟踪文件进行了“禁止”更改:
One approach would be to simply check for the type of changes using
git diff-index --cached HEAD
. This will show you which files are being changed and the type of change being made:So you can parse this output for the change type field:
git diff-index | cut -d ' ' -f 5 | cut -f 1
. This will give you a list of the type of changes being made:And you can simply check for any modifications or deletions and exit the hook if any "disallowed" change was made to tracked files: