在提交前提交钩子之前修改文件

编程入门 行业动态 更新时间:2024-10-28 11:26:39
本文介绍了在提交前提交钩子之前修改文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我试图编写一个预先提交的钩子来修改代码中的一行,但我甚至不知道从哪里开始。

问题是:

我有一个 KEY

public static final String APP_KEY =; //在提交前删除密钥!!!

为了避免将KEY发布到资源库,我想可能git钩子是我们需要手动删除密钥。我查看了 Git Book )

查看示例o f如何在中声明这些过滤器?git能够自动在空格和制表符之间切换吗?

I am trying to write a pre-commit hook that modify a line in my code but I do not know even from where to start.

The problem is:

I have a KEY

public static final String APP_KEY = ""; //DELETE THE KEY BEFORE COMMIT!!!

In order to avoid publishing the KEY to the repository I've think maybe git hooks are the thing we need instead of delete the key manually. I've take a look at Customizing git hooks but I do not know how to write the hook.

Is there a way to before commit the changes, delete the KEy and after the commit write the key again?

解决方案

That would be done with a content filter driver:

  • a clean script which would remove the key on checkin
  • a smudge script which would add it back on checkout.

(image from "Customizing Git Attributes" from the Git Book)

See an example of how those filters are declared in "Can git automatically switch between spaces and tabs?"

更多推荐

在提交前提交钩子之前修改文件

本文发布于:2023-10-13 14:36:18,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1488229.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:钩子   文件

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!