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)
我该怎么做?
您可以使用.gitatrributes来过滤内容:
.gitattributes
secrets.h filter=secret merge=keepMine
Run Code Online (Sandbox Code Playgroud)的.git /配置
[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
Run Code Online (Sandbox Code Playgroud)我投入了'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
归档时间: |
|
查看次数: |
872 次 |
最近记录: |