Reputation: 51
I have some files (i.e some version files) in a remote repository that shouldn't be changed by future commits. Is there a way to make sure that future users who commit to this file will not be able to override the file in the remote, but still be able to push. Is there an easier way to do this than using githooks? I don't want to create a commit that undo's a users change in a githook. Is there a cleaner way of doing this?
Upvotes: 3
Views: 2512
Reputation:
I think what you need based on your need is (I maybe wrong here) is to:-
To temporarily ignore changes in a certain file: run
git update-index --assume-unchanged <file>
Then when you want to track changes again:
git update-index --no-assume-unchanged <file>
http://gitready.com/intermediate/2009/02/18/temporarily-ignoring-files.html
This will retain the file in your git repo. Any local changes made in that file will not be able to be added, committed and pushed to the remote repo.
Upvotes: 7
Reputation: 3341
You don't need to create an additional commit undoing the user's changes if you use a pre-receive
hook. This hook allows you to inspect the changes that are being pushed to your repo, and reject them (all or nothing) if they make changes to the forbidden file(s). Or if you'd prefer to just skip the changes to that file and allow their other changes to be pushed, use an update
hook to reject only the changes to the forbidden files, while allowing the others through. (But this breaks the transactional integrity of their push, so you're making the assumption that the other changes will not depend on the changes they were attempting to make to the forbidden files.)
Upvotes: 0