Git用户配置文件 - 自定义忽略 [英] Git user config file - custom ignore

查看:76
本文介绍了Git用户配置文件 - 自定义忽略的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们有一个由5名开发人员组成的团队负责硬件项目。我们有一个user_config.h文件,其中包含每个用户特定环境和偏好的#defines,例如他们使用的硬件版本,是否打开声音等等。



目前,该文件位于我们的.gitignore文件中,该文件运行良好。用户可以对其设置进行更改,但不会推送。它先前已被追踪过,并且已经在主分支上被rm - 缓存。



偶尔我们切换到一个没有该文件的旧分支,并被删除。然后用户必须让其他人给他们发送一个当前的user_config.h文件。我们希望阻止这种情况发生。



奖励积分:我真正想要的是跟踪文件,但忽略用户更改。偶尔,项目负责人需要在添加新功能时为此文件添加设置,因此我们希望将这些更改推送给所有用户。如果新用户检查回购,我们希望他们获得出厂默认设置,这也可以随时更改。



因此,理想情况下,我们希望忽略文件中任何行的更改,但接受添加或删除行的更改。最好能够临时关闭这个功能,以便我们改变默认设置(即使这意味着直接在github中编辑文件或类似的东西),覆盖回购内容而不是用户的更改。



有没有什么办法可以在git中实现这一切?

解决方案

't track config.h

您可以进行版本跟踪:


  • a config.h.tpl (带占位符值的模板文件)。

  • 一个默认值文件,带有出厂默认设置

  • 脚本能够获取值文件和模板文件,并生成 config.h 文件(它保持未跟踪,私有)

  • a .gitignore which忽略生成的 config.h 文件

  • a .gitattribute 声明一个涂抹内容过滤器(见下面)


    然后,您可以在外面将本地克隆保存为文件,每个开发人员都有自己的私有值。如果脚本没有在repo之外检测到该文件,它将使用默认值文件生成 config.h



    通过

    (图片从自定义Git - Git属性 a> from Pro Git book ))



    一旦您在本地配置中声明了内容文件管理器驱动程序,它会自动在git checkout上生成 config.h 文件为您。

    查看最佳实践 - Git + Build自动化 - 保持配置不同


    We have a team of 5 developers working on a hardware project. We have a user_config.h file containing #defines for each user's specific environment and preferences - eg what hardware version they're using, whether sound should be turned on etc.

    Presently, the file is in our .gitignore file, which works well enough. Users can make changes to their settings that don't get pushed. It was previously tracked and has been rm --cached on master branch.

    Occasionally we switch to an old branch that didn't have the file, and it gets deleted. The user then has to get someone else to email them a current user_config.h file. We'd like to stop this from happening.

    Bonus points: What I'd really like is to have the file tracked, but ignore user changes. Occasionally, the project leads need to add settings to this file when new features are added, so we'd like those changes to be pushed to all users. And if a new user checks out the repo, we'd like them to get the "factory default" settings, which would also be good to change from time to time.

    So, ideally, we want to ignore changes to any line of the file, but accept changes where lines are added or deleted. Preferably with the ability to temporarily turn this off so we can change the defaults, (even if this means editing the file directly in github or something like that), overwriting what's on the repo but not users' changes.

    Is there any way in git that we can achieve all of this?

    解决方案

    Simply don't track config.h.
    You can version and track:

    • a config.h.tpl (template file with placeholder values).
    • a default value file, with the factory default setting
    • a script able to take a value file and a template file, and produce the config.h file (which remains untracked, private)
    • a .gitignore which ignores the resulting generated config.h file
    • a .gitattribute declaring a smudge content filter (see below)

    Then you can keep outside your local clone a value file where each developer will have their own private values. If the script does not detect that file outside the repo, it would generate the config.h with the default value file.

    That generation is automated through a content filter driver, using a .gitattributes declaration.


    (image from "Customizing Git - Git Attributes" from "Pro Git book"))

    Once you declare that content filer driver in your local config, it will automatically, on git checkout, generate your config.h file for you.
    See a complete example in "Best practice - Git + Build automation - Keeping configs separate".

    这篇关于Git用户配置文件 - 自定义忽略的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆