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

后端 未结 5 1361
鱼传尺愫
鱼传尺愫 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:27

    use update-index, here are the docs.

    Here is a basic example freezing a file foo.rb:

    git update-index --assume-unchanged foo.rb
    

    Then, to get it back:

    git update-index --no-assume-unchanged foo.rb
    

    Or for simplicity, add it to .gitconfig

    freeze = update-index --assume-unchanged
    thaw = update-index --no-assume-unchanged
    ...
    git freeze foo.rb
    git thaw foo.rb
    

    Note: This answer was originally provided by @TheAmpersand in comments above. I thought it was important enough to formalize.

提交回复
热议问题