Is there a way to “freeze” a file in Git?

后端 未结 5 1371
鱼传尺愫
鱼传尺愫 2020-12-23 14:40

I\'m in a situation where I want to open source my project, however there\'s a single source file that I want to release a \"clean\" version of, but use a separate version l

5条回答
  •  孤城傲影
    2020-12-23 15:30

    Greg's approach very adequately and precisely answers your question.

    Let me make an addition that takes into account what I infer to be your high-level objectives:

    • Don't release local data to the wild
    • Release a clean version into the wild

    The simplest (and in my experience, best attested) way to accomplish this is to use the following structure:

    Versioned

    ./application.code
    ./config.code
    ./config.local.code.sample
    ./.gitignore
    

    application.code

    include('./config.code')
    if is_file('./config.local.code')
      include('./config.local.code')
    end
    

    config.code

    username = 'root'
    password = 'password'
    

    config.local.code.sample

    username = 'replace with your local username and rename file to config.local.code'
    password = 'replace with your local password and rename file to config.local.code'
    

    .gitignore

    config.local.code
    

    Unversioned (optionally)

    ./config.local.code # will not be picked up by git due to .gitignore
    

    config.local.code

    username = 'Suan'
    password = 'myownpass'
    

    Result

    As you can see, you avoid releasing config.local.code, which actually contains your sensitive information, into the wild. The default configuration (cloned straight from a remote) will work for a reasonable, if rare, case where username root and a password password is valid. And the aptly named config.local.code.sample provides local customization instructions.

提交回复
热议问题