Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I make a file in git read-only?

Tags:

git

git-svn

I'm writing an iOS app that uses a versioned Core Data model.
I just very nearly released a version of the app which crashed on upgrade because I'd accidentally edited the old version as well as creating a new one.

To stop this happening again, I'd like to flag the old versions in some way that prevents any check-in that modifies those files without first removing the flag.

To make things more complicated, I'm using git-svn, so having a read-only repo as a submodule won't work.

like image 224
Simon Avatar asked May 28 '13 14:05

Simon


1 Answers

Basically you cant.
Git will track changes done with chmod if you did not turn the flag off.

You can use some workaround to do it.

  • Git hook

    Verify in your both local & server hooks that the desired file is not part of the diff which means that it was not modified.

    Why in both?

    Since local hooks can be removed y user so you want to verify it in the server. can be done in the pre-receive or update hooks.


  • Read-only submodule

    Place the file in a separate repository and use it as submodule. This repository will be read-only for all users except the ones which you allow to write to.
    I don't know what is your git server but most of the servers support read only or lock to any given branch.

  • git update-index --assume-unchanged

    it makes Git to omit any checking and assume it has not changed. When you make changes to working tree files, you have to explicitly tell Git about it by dropping "assume unchanged" bit, either before or after you modify them.

This will "ignore" any local changes made to this file.

like image 128
CodeWizard Avatar answered Oct 03 '22 23:10

CodeWizard