Search code examples
gitpermissions

How can i restore the permissions of files and directories within git if mistakenly denied access?


I am new to coding and I was trying to figure out how to commit in my terminal. I executed the command git add -A and git started asking for permission to all my files I denied them not putting much thought into it (I freaked out I didn't know if it's a trusted source i'm still learning). But now I've gotten myself into an even bigger problem. When I try to create a file now I am unable to due not having access to my files through git.

A warning pops up that says:

error: open("Library/Application Support/FileProvider/8B7B18C3-4F13-4F7D-A0CD-EF8531215A66/wharf/tombstone/a"): Permission denied
error: unable to index file 'Library/Application Support/FileProvider/8B7B18C3-4F13-4F7D-A0CD-EF8531215A66/wharf/tombstone/a'
fatal: adding files failed

I'm really at a loss if anyone can give me a step by step guide as to how I have resolve this I would really appreciate it! thank you!

Not to mention I have tried just about everything to resolve this nothing is working!!!

  • I closed the application and restarted it.
  • I've ran chmod +x on each file to give access.
  • I've accessed system settings/privacy&security and allowed access.
  • I've ran chmod chmod 777.

Solution

  • It looks like you've created a repository in your home directory, which is almost never a good idea, because a repository controls all the files under it, and typically you don't want all of your home directory in one repository.

    On macOS, some files are restricted in certain ways beyond the standard Unix permissions and the standard Unix interfaces Git uses, which is why you're seeing this error, since you're trying to add these files.

    It is also a bad idea to mark files 0777, since that allows every user on your system to write to your files. Even if this is only your laptop, there are services running on it that are specifically run with low privileges so if there's a security problem, they can't access most files, and then you've just made it possible for that service to tamper with those files.

    What you probably want to do here is get rid of the .git directory in your home directory by doing mv ~/.git ~/.git.bak. That will move it to the side, so you don't lose any data, and then later on, when you're sure you don't need it, you can delete .git.bak.

    Then, you can change into a directory specific to the project you're working on and run git init. You can then run git add and git commit as you like, and it won't try to add files outside of that directory. That means all your project files need to be in that directory or a subdirectory of it, but that's generally what you want anyway.