I would like to make sure that all changes people make to files in a shared directory are tracked - committed in Git. I have found ways to avoid making the commit if a file is changed, however I haven't figured out a way to make sure that every user is forced to commit their changes.

  • Are we talking about shared files in a (Git) project directory? Or just some directory on a server? Of perhaps on an NFS share? Please elaborate on your use-case. – mtak Feb 15 '17 at 9:53
  • In a shared directory - I updated the question to reflect it. – Lefty G Balogh Feb 15 '17 at 10:13
  • Just brainstorming, but how would the kernel enforce something like that? Give RW access, but only write the file to disk if someone did a Git commit (which git would not pick up, because the file on disk hasn't changed yet)? Users would always be able to change the file, and then logoff, even if git asks them for a commit message for example. And what would happen if someone didn't have an ssh key installed, but does have write access to the file? You could make a shell wrapper of some sort, so people don't forget to commit, but strictly enforcing it seems impossible. – mtak Feb 15 '17 at 10:21
  • Exactly. I was hoping you wouldn't say that, though. That is exactly my problem and I am trying to find an ingenious way around it. I can ensure that whoever changes the file has proper Git credentials, but making then do the commit is the challenge here. – Lefty G Balogh Feb 15 '17 at 10:25
  • 1
    It sounds like you're misusing git. You need something like append-only file system. If you insist on sticking to git, make the shared folder a read-only bare repository and let users push to it. – gronostaj Feb 15 '17 at 10:54

The easiest way of enforcing that is to revoke write rights to that directory. Have the users do changes in their own clone, push to the central repository, and rely on post-receive hook scripts to update the "main" directory.

  • Thanks. Definitely worth an upvote. Can you see any way to avoid local clones? – Lefty G Balogh Feb 16 '17 at 13:06
  • 1
    No. As long as people can edit "live" files directly, they can edit files directly – you can't make the PC jail them in until they git-commit the edits, or whatever. – grawity Feb 16 '17 at 13:09

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.