Git用户配置文件 - 自定义忽略 [英] Git user config file - custom ignore
问题描述
目前,该文件位于我们的.gitignore文件中,该文件运行良好。用户可以对其设置进行更改,但不会推送。它先前已被追踪过,并且已经在主分支上被rm - 缓存。
偶尔我们切换到一个没有该文件的旧分支,并被删除。然后用户必须让其他人给他们发送一个当前的user_config.h文件。我们希望阻止这种情况发生。
奖励积分:我真正想要的是跟踪文件,但忽略用户更改。偶尔,项目负责人需要在添加新功能时为此文件添加设置,因此我们希望将这些更改推送给所有用户。如果新用户检查回购,我们希望他们获得出厂默认设置,这也可以随时更改。
因此,理想情况下,我们希望忽略文件中任何行的更改,但接受添加或删除行的更改。最好能够临时关闭这个功能,以便我们改变默认设置(即使这意味着直接在github中编辑文件或类似的东西),覆盖回购内容而不是用户的更改。
有没有什么办法可以在git中实现这一切?
't track 然后,您可以在外面将本地克隆保存为值文件,每个开发人员都有自己的私有值。如果脚本没有在repo之外检测到该文件,它将使用默认值文件生成 通过 一旦您在本地配置中声明了内容文件管理器驱动程序,它会自动在git checkout上生成 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 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 That generation is automated through a content filter driver, using a Once you declare that content filer driver in your local config, it will automatically, on git checkout, generate your 这篇关于Git用户配置文件 - 自定义忽略的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋! config.h
。
您可以进行版本跟踪:
config.h.tpl
(带占位符值的模板文件)。
config.h
文件(它保持未跟踪,私有)
.gitignore
which忽略生成的 config.h
文件
.gitattribute
声明一个涂抹内容过滤器(见下面)
config.h
。
(图片从自定义Git - Git属性 a> from Pro Git book ))
config.h
文件为您。
查看最佳实践 - Git + Build自动化 - 保持配置不同。config.h
.
You can version and track:
config.h.tpl
(template file with placeholder values). config.h
file (which remains untracked, private).gitignore
which ignores the resulting generated config.h
file.gitattribute
declaring a smudge content filter (see below)config.h
with the default value file..gitattributes
declaration.
(image from "Customizing Git - Git Attributes" from "Pro Git book"))config.h
file for you.
See a complete example in "Best practice - Git + Build automation - Keeping configs separate".