致命:无法创建临时文件“/home/username/git/myrepo.git/./objects/pack/tmp_pack_XXXXXX”:权限被拒绝

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/13146992/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-10 14:50:47  来源:igfitidea点击:

fatal: Unable to create temporary file '/home/username/git/myrepo.git/./objects/pack/tmp_pack_XXXXXX': Permission denied

git

提问by rjd

I have been having trouble with this error message and I don't understand the proper solution to fix it or go about debugging it. I have googled the error in various forms but no real solution has presented itself. I am assuming it's an issue with permissions but I don't really know how to check or what I should check for.

我一直遇到此错误消息的问题,我不明白修复它或调试它的正确解决方案。我已经以各种形式搜索了错误,但没有提出真正的解决方案。我假设这是权限问题,但我真的不知道如何检查或应该检查什么。

I have a server running Ubuntu 11.10 and I'm basically trying to make the initial commit to my git repo from my development machine. I'm running as root. Should I be running as the user?

我有一台运行 Ubuntu 11.10 的服务器,我基本上是在尝试从我的开发机器对我的 git repo 进行初始提交。我以 root 身份运行。我应该以用户身份运行吗?

Repo creation on server:

在服务器上创建回购:

$ cd /home/username/git
$ mkdir myrepo.git
$ cd myrepo.git/
$ git --bare init

Repo creation on development machine:

在开发机器上创建仓库:

Goto rails project directory first
$ git init
$ git add .
$ git commit -m "initial commit"
$ bundle pack
$ git add Gemfile.lock vendor/cache
$ git commit -m "bundle gems"
$ git remote add origin ssh://[email protected]/home/username/git/myrepo.git
$ git push origin master

Error:

错误:

fatal: Unable to create temporary file '/home/username/git/myrepo.git/./objects/pack/tmp_pack_XXXXXX': Permission denied
error: pack-objects died of signal 13
error: failed to push some refs to 'ssh://[email protected]/home/username/git/myrepo.git'

My .git/config file:

我的 .git/config 文件:

[core]
    repositoryformatversion = 0
    filemode = true
    bare = false
    logallrefupdates = true
    ignorecase = true
[remote "origin"]
    url = ssh://[email protected]/home/username/git/myrepo.git
    fetch = +refs/heads/*:refs/remotes/origin/*

Similar question: How do I do an initial push to a remote repository with Git?

类似问题: 如何使用 Git 对远程存储库进行初始推送?

回答by Don Branson

It sounds like you have file in the git repo owned by root. Since you're ssh'ing in as 'username' to do the push, the files must be writable by username. The easiest thing is probably to create the repo as the user, and use the same user to do your pushes. Another option is to create a group, make everything writable by the group, and make your user a member of that group.

听起来您在 root 拥有的 git 存储库中有文件。由于您以“用户名”身份进行推送,因此文件必须可由用户名写入。最简单的方法可能是以用户身份创建 repo,并使用相同的用户进行推送。另一种选择是创建一个组,使该组可以写入所有内容,并使您的用户成为该组的成员。

回答by rjd

Ok, I figured it out. The issue was that I didn't have the correct permissions set for myrepo.git and the parent directory git.

好的,我想通了。问题是我没有为 myrepo.git 和父目录 git 设置正确的权限。

As root I logged into the server and used:

我以 root 身份登录服务器并使用:

$ chown username /home/username/git

This then returns drwxrwxr-x 4 username root 4096 2012-10-30 15:51 /home/username/git with the following:

然后返回 drwxrwxr-x 4 username root 4096 2012-10-30 15:51 /home/username/git 并带有以下内容:

$ ls -ld /home/username/git

I then make a new directory for myrepo.git inside git:

然后我在 git 中为 myrepo.git 创建一个新目录:

$ mkdir myrepo.git
$ ls -ld myrepo.git/
drwxr-xr-x 2 root root 4096 2012-10-30 18:41 myrepo.git/

but it has the user set to root, so I change it to username the same way as before.

但它的用户设置为root,所以我像以前一样将其更改为用户名。

$ chown username myrepo.git/
$ ls -ld myrepo.git/
drwxr-xr-x 2 username root 4096 2012-10-30 18:41 myrepo.git/

I then sign out of root and sign into server as username:

然后我退出 root 并以用户名登录服务器:

Inside git directory:

在 git 目录中:

$ cd myrepo.git/
$ git --bare init
Initialized empty Git repository in /home/username/git/myrepo.git/

On local machine:

在本地机器上:

$ git remote add origin      
ssh://[email protected]/home/username/git/myrepo.git
$ git push origin master

SUCCESS!

成功!

Hopefully this comes in handy for anyone else that runs into the same issue in the future!

希望这对将来遇到相同问题的其他人有用!

Resources

资源

回答by Ryan Bigg

It would seem like your user doesn't have permission to write to that directory on the server. Please make sure that the permissions are correct. The user will need write permissions on that directory.

您的用户似乎无权写入服务器上的该目录。请确保权限正确。用户将需要对该目录的写权限。

回答by sundogya

Thanks to Don Branson,I solve my problem.I think next time i should use this code when i build my repo on server:

感谢 Don Branson,我解决了我的问题。我想下次我在服务器上构建我的 repo 时应该使用这个代码:

root@localhost:~#mkdir foldername
root@localhost:~#cd foldername
root@localhost:~#git init --bare
root@localhost:~#cd ../
root@localhost:~#chown -R usergroup:username foldername

And on client,i user this

在客户端,我使用这个

$ git remote add origin git@servername:/var/git/foldername
$ git push origin master

回答by Robert Stoddard

One of the principal issues with pushing to a GIT is that the material you push will appear as your material, and will block submissions from other people on a team. As a GIT repository administrator, you will have to manage the hooks to prevent Alice's push from blocking Bob from pushing. To do that, you will want to ensure that your developers all belong to a group, lets call it 'developers' and that the repository is owned by root:developers, and then add this to the hooks/post-update script:

推送到 GIT 的主要问题之一是您推送的材料将显示为您的材料,并且会阻止团队中其他人的提交。作为 GIT 存储库管理员,您必须管理挂钩以防止 Alice 的推送阻止 Bob 推送。为此,您需要确保您的开发人员都属于一个组,让我们称其为“开发人员”并且存储库归 root:developers 所有,然后将其添加到 hooks/post-update 脚本中:

sudo chown -R root:developers $GIT_DIR
sudo chmod -R g+w $GIT_DIR

That will make it so that team members are able to push to the repository without stepping on each other's toes.

这将使团队成员能够推送到存储库而不会相互影响。

回答by Тимофей Левендеев

Just try to do this one (through root access) - "chmod -R 777 /home/username/git"

尝试执行此操作(通过 root 访问)-“chmod -R 777 /home/username/git”

回答by Snow

I resolved it by giving permission to the user on each of the directories that you're using, like so:

我通过向用户授予您正在使用的每个目录的权限来解决它,如下所示:

sudo chown user /home/user/git

and so on.

等等。

回答by Larry

A possibility is that the git server you are pushing to is down/crashed, and the solution lies in restarting the git server.

一种可能是您要推送到的 git 服务器已关闭/崩溃,解决方案在于重新启动 git 服务器。