The Bear
The Bear

Reputation: 51

Is there a way to prevent a commit to a file in a remote repository?

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

Answers (2)

user5574289
user5574289

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

David Scarlett
David Scarlett

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

Related Questions