git - 使用 git hook 添加许可证和应用程序版本以在源文件顶部注释

标签 git hook

我正在尝试为 git 创建一个预提交 Hook ,用于编辑我的每个 .h 和 .m 文件顶部的注释。我想更改 x-code 添加的标题注释以包含应用程序版本和许可证信息。这在更改为新版本时会很有帮助。

这是我在 x-code 中创建文件时自动插入的文本:

//
//  myFile.h
//  myApp 
//
//  Created by Developer on 11/13/12.
//  Copyright (c) 2012 myCompany LLC. All rights reserved.
//

我希望钩子(Hook)将其更改为:

/*

myFile.h
myApp
Version: 1.0

myApp is free software: you can redistribute it and/or modify it under the terms 
of the GNU General Public License as published by the Free Software Foundation,
either version 2 of the License, or (at your option) any later version.

myApp is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; 
without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 
PURPOSE.  See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with myApp.
If not, see <http://www.gnu.org/licenses/>

Copyright 2012 myCompany. All rights reserved.


This notice may not be removed from this file.

*/

我想我会有一个文本文件,其中包含我想要更改的标题文本。或者检测应用程序版本号何时更改。当此文件更新为新版本号并且 git 我执行 git commit 时,它将使用新版本更新所有其他文件并更改所有新文件以具有正确的标题文本。这似乎很有用。

最佳答案

使用smudge/clean filters (整章,最仔细地链接“关键字扩展”)?

关于git - 使用 git hook 添加许可证和应用程序版本以在源文件顶部注释,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14419517/

相关文章:

git - 为 GIT 标签设置特定日期

git - 在 git jenkins 中找不到存储库

php - WooCommerce 为重新计算按钮添加订单管理 Hook

svn - 如何添加多个 SVN Hooks

c++ - 在 Winx64 上使用 User32InitializeImmEntryTable?

php - Woocommerce 订单状态 Hook 不适用于 PayPal 交易

Git-忽略子目录中的某些文件,但不是全部

c++ - libgit : Fastest way of fetching files in a commit

git - 我可以从 .git/info/exclude 覆盖 .gitignore 中的任何忽略规则吗

ios - 这是如何工作的? - 越狱调整