我如何将一个虚拟文件放在一个git仓库中? [英] How do I place a dummy file in a git repo?

查看:172
本文介绍了我如何将一个虚拟文件放在一个git仓库中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是git的新手,请耐心等待。

假设我在包含敏感数据的版本控制下有一个文件。果然,我把这个文件放在我的.gitignore文件中,所以它不会被推到回购站。现在的问题是在我的项目中的某个地方,我有一行像

  #include< sensitivedata> 

或任何您选择的语言。
问题是每当有人从该repo克隆时,该文件丢失,并且在尝试构建/编译该解决方案时遇到致命错误。

因此,而不是推送我实际上正在处理的文件我想用相同的名称推送一些虚拟文件,而我在这里放置注释,如

  //用敏感数据替换下一行! 

我会怎么做?

解决方案

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


  • .gitattributes

      secrets.h filter = secret merge = keepMine 


  • .git / config

      [过滤秘密] 
    clean = echo//将下一行替换为敏感数据
    smudge = cat

    [mergekeepMine]
    name =在合并期间始终保留我的
    driver = / bin / true%O%A%B




我投入了keepMine合并以防止意外合并。然而,由于 clean 过滤步骤,本地更改将有效隐藏,因此AFAIK合并甚至不应该启动。无论 secrets.h 中的内容如何,​​回购文件将始终包含:

  //用敏感数据替换下一行

例如:


> / tmp / work $ echo'/ /代理007报税> secrets.h

/ tmp / work $ git status -s

M secrets.h

/ tmp / work $ git diff

/ tmp / work $ git cat-file -p HEAD:secrets.h

//秘密内容不在回购中



I'm new at git so please bear with me.

Say i have a file under version control that includes sensitive data. Sure enough, I put that file in my .gitignore file, so it doesn't get pushed to the repo. The problem now is somewhere in my project i have a line like

#include <sensitivedata>

or whatever your language of choice is. The problem is whenever somebody clones from that repo, that file is missing and he gets a fatal error when trying to build / compile the solution.

So, instead of pushing the file I'm actually working on I want to push some dummy file with the same name instead, where I place a comment like

// replace the next line with the sensitive data!!!

How would I do this?

解决方案

You could use .gitatrributes to filter the contents:

  • .gitattributes

    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
    

I threw in a 'keepMine' merge to prevent accidental merges. However, AFAIK merge should not even kick in, as local changes would be effectively 'invisible' due to the clean filter step. Regardless of what's actually in secrets.h, the repo file will always contain:

// replace the next line with the sensitive data

E.g.:

/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仓库中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆