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

ⅰ亾dé卋堺 提交于 2019-11-28 16:41:29

This is not an error message from the remote Git repository, this is a problem with your local files. You probably used git (or rake) as another user (such as root) in this same directory, and it created files which you now can't overwrite.

Simply use chown to change the ownership of the files to your current user, for instance:

chown -R $(whoami) .

I solved it by deleting .git/COMMIT_EDITMSG. Weird, I know.

If you are working on the bloody Microsoft Windows the error might be due to the fact that you are "watching" the hidden files in the file explorer..that´s it!

another solution for Windows users: if you are using YandexDisk - and your .git folder under syncronisation - YandexDisk set hidden and readonly attributes after syncronisations. So, switch off YandexDisk and make .git folder and all subfolders and files NOT invisible and not readonly

Michael Dunn

chmod 664 the file .git/COMMIT_EDITMSG gives it group write permissions.

In my situation the file was owned by another user who was part of my development group. Giving it group write permissions solved it.

The .git directory should be in the root of your repository.

Command (assuming you are in the .git directory):

chmod 664 COMMIT_EDITMSG 

This tends not to be a permissions issue.

This situation may occur when you are prompted to record a commit message when merging (for example) and you don't save and quit the text editor but you simply quit.

Git seems to assume there is still someone editting a commit message and refuses to overwrite the existing file as it would cause unexpected behaviour and loss of another commit message.

If you are using Windows and you are stuck with any Git permission issues, make sure your (local) repository's .git folder contents are not marked as hidden.

You can however hide the directory itself, just not it's contents (files, subdirectories).

If you're using TortoiseGit, you may have a Commit dialog already open

In my case, the reason is that the current user(A) is not COMMIT_EDITMSG file owner(B), change current user to B and commit again. sudo su B

Simply run on your command line : chmod 777 -Rf /var/www/html/project-name/.git

Quick note:

If you have set a file to hidden/readonly this can occur to. Try setting the whole folder to unhidden and uncheck readonly.

I'm working with VSCODE and windows when I do home office (I don't like windows). And I fix this problem closing de VSCODE and doing de git pull

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!