简体   繁体   English

GIT:如何将文件添加到 repo 但忽略它进行更改

[英]GIT: How to add file to repo but ignore it for changes

I have a file with app configuration.我有一个包含应用程序配置的文件。 I want to add this file to the repo so everyone could have basic configuration but ignore any changes in file if someone will want to modify configuration.我想将此文件添加到 repo 中,这样每个人都可以拥有基本配置,但如果有人想要修改配置,则忽略文件中的任何更改。

I know about assume-unchanged but it looks like it is only for local repo, when somebody will clone the repo and change this file git will mark it as modified.我知道assume-unchanged但它看起来仅适用于本地存储库,当有人克隆存储库并更改此文件时,git 会将其标记为已修改。

Thanks.谢谢。

Even if there is a technical solution to the problem, I don't think you should seek it.即使问题有技术解决方案,我认为您也不应该寻求它。 As a user of your repository, if I kept changing this one file and it wasn't showing up in my stage, I'd be very confused.作为您存储库的用户,如果我不断更改这个文件并且它没有出现在我的舞台上,我会非常困惑。

Mark the file as do not edit, either in a comment in the file, or in the readme if the file does not allow comments.在文件中的注释中或在自述文件中(如果文件不允许注释)将文件标记为不可编辑。

Then, if someone wants to make modifications to it and sees it in stage, it's their responsibility to set an ignore on the file.然后,如果有人想对其进行修改并在阶段查看它,则他们有责任对文件设置忽略。

  • Call your configuration config-template.conf and provide that through the repo.调用您的配置config-template.conf并通过 repo 提供它。
  • In the README, instruct users to rename the template to config.conf which your application expects to find.在自述文件中,指示用户将模板重命名为您的应用程序希望找到的config.conf
  • Add config.conf to your .gitignore .config.conf添加到您的.gitignore

The config.conf will not be tracked.不会跟踪config.conf

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM