Search code examples
gitpermissionscommit

git- Committing using an editor for the message: The document “COMMIT_EDITMSG” could not be opened. You don’t have permission


I have a git repository, to which I could commit without any issues from other computers in the past. Now, on a new computer, I clone the repository, modify a file, and add it.

Then, I try commit, and apparently I had not set up editor correctly, so instead of TextEdit opening (which I wanted) Vi opens in the terminal editing the file. Vi is closed abnormally, and then I set up in bash the editor correctly, and try again. I try to commit using TextEdit (or other editors after that) to write the commit message, I get the following message in a popup window: 'The document “COMMIT_EDITMSG” could not be opened. You don’t have permission.'

This does not happen when I use git commit -m"..." in the terminal.

I know there are a few threads with relevant topics, which I have seen. For example: About fatal: could not open '.git/COMMIT_EDITMSG': Permission denied

could not open git/commit_editmsg

fatal: could not open '.git/COMMIT_EDITMSG': Permission denied

or

"unable to append to .git/logs/refs/heads/master" when commiting

to name a few.

I tried doing several things mentioned in them:

  • chmod -R u+x .git
  • sudo chown -Rc $UID .git/ (and got the message "chown: illegal option -- c")
  • chmod 664 COMMIT_EDITMSG
  • delete the file COMMIT_EDITMSG
  • git init --shared=0777
  • delete the local repository from hard disk, clone from GitHub, and try again

So far no luck. I can only commit doing git commit -m"..." (and then successfully push to remote), but never using an editor for writing the message.

In case it helps, OS is macOS Sierra.

If anyone has any idea what I could be doing wrong, or what I missed in the relevant topics, I would be grateful.


Solution

  • okay, after a lot of tries at different occasions, I found something that actually worked in my case:

    I went and edited the config file in my local git repository. there, under [core], I added the following:

    editor = open -a TextEdit -W

    (using TextEdit as the desired editor)

    For some reason, when I had the same in my bash profile file, the result was not the same...