Version control 如何在git回购中放置虚拟文件?
我是git的新手,所以请容忍我 假设我有一个受版本控制的文件,其中包含敏感数据。果不其然,我将该文件放在了.gitignore文件中,这样它就不会被推送到repo。现在的问题是在我的项目中我有一行Version control 如何在git回购中放置虚拟文件?,version-control,git-commit,git-add,git,Version Control,Git Commit,Git Add,Git,我是git的新手,所以请容忍我 假设我有一个受版本控制的文件,其中包含敏感数据。果不其然,我将该文件放在了.gitignore文件中,这样它就不会被推送到repo。现在的问题是在我的项目中我有一行 #include <sensitivedata> 我该怎么做?您可以使用.gitatributes来过滤内容: .gittributes secrets.h filter=secret merge=keepMine .git/config [filter "secret"] cle
#include <sensitivedata>
我该怎么做?您可以使用.gitatributes来过滤内容:
- .gittributes
secrets.h filter=secret merge=keepMine
- .git/config
[filter "secret"] clean = echo "// replace the next line with the sensitive data" smudge = cat [merge "keepMine"] name = always keep mine during merge driver = /bin/true %O %A %B
clean
filter步骤,本地更改实际上是“不可见的”。无论secrets.h
中实际包含什么,回购文件始终包含:
// replace the next line with the sensitive data
例如:
/tmp/work$
echo'//agent 007报告职务秘密.h
/tmp/work$
git status-s
M secrets.h
/tmp/work$
git diff
/tmp/work$
git cat文件-p头:secrets.h
//不在回购中的秘密内容
我不知道C++预处理器是否能做到这一点(我假设上面的代码是针对C型预处理器的),但下面是我在类似的例子中所做的:
在git中提交:- default.config
- user.config.template
- user.config
if (file_exists(user.config)):
use user.config
else:
use default.config
这样我就可以提供一些合理的默认设置,并有一个简单而干净的方法来覆盖它。a提醒:
。git/config
文件是本地的。您需要确保此repo的所有用户都具有过滤器定义,因为.gittributes
在repo中。您可能需要阅读更多详细信息谢谢您的输入。我的想法与您的想法相同,但后来决定反对,因为我完全想将任何源代码控制问题与实际代码分开。为了完整起见,如果其他人想走这条路,可以在makefile中使用如下内容:
if (file_exists(user.config)):
use user.config
else:
use default.config