git无法打开.git/FETCH_HEAD文件

20

我有CentOs操作系统。我使用git并将所有者的.git文件夹设置为“gitdevelopers”组。在组“gitdevelopers”中添加了User1和User2用户。现在,当用户1和用户2进行git-push和git-pull更改时,其他电脑上的用户会出现以下错误:

git.exe pull -v --no-rebase --progress "origin" error: cannot open .git/FETCH_HEAD: Permission denied

为什么会这样?

附言:我可以通过x-shell使用用户1和用户2的登录密码连接到服务器。

几小时后: 我认为问题在于git记住了错误的登录密码。

附言:git保存登录密码对吗?我使用ssh协议。

再次说明:我有一个CentOs服务器,上面有两个用户。我使用TortoiseGit在Windows上进行配置:每次连接系统都会要求输入登录名和密码以连接到服务器。现在,我想知道:1.保存这个登录密码对的位置在哪里?2.我可以永久地保存这个对吗?


你尝试过在服务器上的.git仓库中使用git config core.sharedRepository true命令吗?并且像这个链接http://serverfault.com/a/27040/783中所示,使用chmod命令。 - VonC
你在联系远程时使用的是什么协议?https?ssh? - VonC
1
ssh 意味着没有登录/密码,只有公钥和私钥存储在 ~/.ssh/ (id_rsa.pub, id_rsa) 中。 - VonC
只要你继续使用“login”和“password”,你的SSH URL就不会起作用。 - VonC
6个回答

64

这对我有效

sudo chown -R $(whoami) .git/

它运行得很好。你能解释一下背后的逻辑吗? - Tarun Nagpal
sudo chown=更改目录所有权, -R=使其递归,即包括该目录内的所有子文件夹和文件, $(whoami)=获取当前登录用户, .git/=存储有关git仓库信息的文件夹, 因此,此命令将文件的所有权更改为当前用户,以便该用户可以执行诸如“git pull”等命令。 - Hasnat Safder

3

如果您正在使用Ubuntu,请在使用之前使用sudo关键字。

sudo git pull

如果您使用的是Windows系统,请使用管理员模式。


2

您可以检查文件的权限,

ls -l /usr/local/Library/Taps/linode/cli/.git/FETCH_HEAD

以及

ls -l /usr/local/.git/FETCH_HEAD


0

我删除了现有的解决方案,重新进行git克隆,这样问题就解决了。


0

这个对我有用:

sudo chown -R $ USER: name_repo

注意: 在我的情况下,我使用root用户克隆了存储库,然后开始使用另一个用户。


0

生成新的SSH密钥对

ssh-keygen -o -t rsa -b 4096 -C "email@domain.com"

将SSH密钥添加到您的GitLab账户

Copy your public SSH key to the clipboard and paste it into your user account >  SSH Keys 

要进行身份验证,您需要在~/.ssh/config中设置以下内容的配置;

Host domain.com

Hostname domain.com

User git

Port 30001

Preferredauthentications publickey

RequestTTY no

IdentityFile ~/.ssh/id_rsa

您可以使用以下命令; 这些命令中提到了常见变量,请替换相关值。

创建新存储库

git clone ssh://git@domain.com:port-number/user-name/project-name.git

cd project-name

touch README.md

git add README.md

git commit -m "add README"

git push -u origin master

推送一个已存在的文件夹

cd existing_folder

git init

git remote add origin ssh://git@domain.com:port-number/user-name/project-name.git

git add .

git commit -m "Initial commit"

git push -u origin master

推送现有的 Git 仓库

cd existing_repo

git remote rename origin old-origin

git remote add origin ssh://git@domain.com:port-number/user-name/project-name.git

git push -u origin --all

git push -u origin --tags

克隆代码库:

git clone https://git@domain.com:port-number/user-name/project-name.git


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接