如何在git仓库中放置一个虚拟文件?

lig*_*txx 7 git version-control git-add git-commit git-commands

我是git的新手所以请耐心等待.

假设我有一个包含敏感数据的版本控制下的文件.果然,我将该文件放在我的.gitignore文件中,因此它不会被推送到repo.现在的问题是在我的项目中的某个地方我有一条线

#include <sensitivedata>
Run Code Online (Sandbox Code Playgroud)

或者你选择的语言是什么.问题是每当有人从该存储库中克隆时,该文件丢失并且在尝试构建/编译解决方案时会出现致命错误.

所以,而不是推送我正在实际工作的文件,我想推送一些具有相同名称的虚拟文件,我在那里发表评论

// replace the next line with the sensitive data!!!
Run Code Online (Sandbox Code Playgroud)

我该怎么做?

seh*_*ehe 7

您可以使用.gitatrributes来过滤内容:

我投入了'keepMine'合并以防止意外合并.但是,AFAIK合并甚至不应该启动,因为由于clean过滤步骤,局部变化将实际上是"不可见的" .无论实际上是什么secrets.h,repo文件将始终包含:

// replace the next line with the sensitive data
Run Code Online (Sandbox Code Playgroud)

例如:

/tmp/work$ echo '// agent 007 reporting for duty' > secrets.h
/tmp/work$ git status -s
M secrets.h
/tmp/work$ git diff
/tmp/work$ git cat-file -p HEAD:secrets.h
// secret contents not in repo

  • 单挑:`.git/config`文件是本地的.您需要确保此repo的所有用户都具有过滤器定义,因为`.gitattributes`位于repo中.您可能需要阅读[git-attributes手册页](https://www.kernel.org/pub/software/scm/git/docs/gitattributes.html)以获取更多详细信息 (2认同)