简体   繁体   English

在流浪机器中没有 sudo 的 Git 命令无法正常工作

[英]Git commands not working without sudo in vagrant machine

I have a project on my vagrant machine that I would like to push into my github repository.我的流浪机器上有一个项目,我想将其推送到我的 github 存储库中。 But I cannot add objects without using sudo .但是我不能在不使用sudo情况下添加对象。

  1. I have initialized git我已经初始化了 git
     vagrant@vagrant:/vagrant/testDir$ git init Initialized empty Git repository in /vagrant/testDir/.git/`
  2. After that if I run the command to add contents之后,如果我运行命令添加内容
    vagrant@vagrant:/vagrant/testDir$ git add .`
    Then I am getting this error:然后我收到此错误:

error: insufficient permission for adding an object to repository database .git/objects错误:将对象添加到存储库数据库 .git/objects 的权限不足

error: file1: failed to insert into database错误:file1:插入数据库失败

error: unable to index file file1错误:无法索引文件 file1

fatal: adding files failed致命:添加文件失败

Although I can run the command without any errors if I run with sudo , ie, sudo git add .虽然我可以在没有任何错误的情况下运行sudo ,即sudo git add . . .

I have confirmed the permission inside the project, and they are are okay:我已经确认了项目内部的权限,他们没问题:

vagrant@vagrant:/vagrant/testDir$ ls -al
total 0
drwxr-xr-x 1 vagrant vagrant 160 Dec 23 10:33 .
drwxr-xr-x 1 vagrant vagrant 160 Dec 23 10:33 ..
drwxr-xr-x 1 vagrant vagrant 352 Dec 23 10:33 .git
-rw-r--r-- 1 vagrant vagrant   0 Dec 23 10:33 file1
-rw-r--r-- 1 vagrant vagrant   0 Dec 23 10:33 file2.txt

I have ubuntu 18.04 on my vagrant machine running on macOS High Sierra.我在 macOS High Sierra 上运行的流浪机器上有 ubuntu 18.04。 Vagrant = 2.2.2 Virtual box = 6.0.8 r130520 Vagrant = 2.2.2 虚拟盒子 = 6.0.8 r130520

Could you please help me out?你能帮我一下吗?

Update 1更新 1

Also, the permission on .git/ directory are fine此外,对.git/目录的权限很好

vagrant@vagrant:/vagrant/testDir/.git$ ls -al
total 12
drwxr-xr-x 1 vagrant vagrant 320 Dec 23 10:52 .
drwxr-xr-x 1 vagrant vagrant 160 Dec 23 04:12 ..
-rw-r--r-- 1 vagrant vagrant  23 Dec 23 04:12 HEAD
drwxr-xr-x 1 vagrant vagrant  64 Dec 23 04:12 branches
-rw-r--r-- 1 vagrant vagrant 111 Dec 23 04:12 config
-rw-r--r-- 1 vagrant vagrant  73 Dec 23 04:12 description
drwxr-xr-x 1 vagrant vagrant 416 Dec 23 04:12 hooks
drwxr-xr-x 1 vagrant vagrant  96 Dec 23 04:12 info
drwxr-xr-x 1 vagrant vagrant 160 Dec 23 04:12 objects
drwxr-xr-x 1 vagrant vagrant 128 Dec 23 04:12 refs

Update 2更新 2

The permission inside the .git/objects directory are also okay. .git/objects目录里面的权限也是可以的。

vagrant@vagrant:/vagrant/testDir/.git/objects$ ls -al
total 0
drwxr-xr-x 1 vagrant vagrant 160 Dec 23 11:06 .
drwxr-xr-x 1 vagrant vagrant 320 Dec 23 11:06 ..
drwxr-xr-x 1 vagrant vagrant  96 Dec 23 11:06 e6
drwxr-xr-x 1 vagrant vagrant  64 Dec 23 11:06 info
drwxr-xr-x 1 vagrant vagrant  64 Dec 23 11:06 pack

These are the steps I took to solve my problem:这些是我为解决问题而采取的步骤:

  1. I downgraded the virtualbox on my macOS from 6.0.8 r130520 to 6.0.4 r128413.我将 macOS 上的 virtualbox 从 6.0.8 r130520 降级到 6.0.4 r128413。
  2. Installed vagrant-vbguest plugin安装vagrant-vbguest插件

    $ vagrant plugin install vagrant-vbguest

  3. Reload the vagrant machine.重新加载流浪机器。

    user@MacBook-Pro vagrant-project-machine $ vagrant reload ==> default: Attempting graceful shutdown of VM... ==> default: Checking if box 'bento/ubuntu-18.04' is up to date... ... ... ==> default: Machine booted and ready! ... [default] GuestAdditions versions on your host (6.0.4) and guest (6.0.8) do not match. ... ... The following additional packages will be installed: linux-headers-4.15.0-51 ... ...

Finally you can confirm it by running this command:最后,您可以通过运行以下命令来确认:

user@MacBook-Pro vagrant-project-machine $ vagrant vbguest --status
...
...
[default] GuestAdditions 6.0.4 running --- OK.

You can also confirm inside the vagrant machine by running this command:您还可以通过运行以下命令在 vagrant 机器内部进行确认:

vagrant@vagrant:/vagrant/testDir$ modinfo vboxguest
filename:       /lib/modules/4.15.0-51-generic/misc/vboxguest.ko
version:        6.0.4 r128413
license:        GPL
description:    Oracle VM VirtualBox Guest Additions for Linux Module
author:         Oracle Corporation
srcversion:     95F53B9B95BC6E03156A1D8
alias:          pci:v000080EEd0000CAFEsv00000000sd00000000bc*sc*i*
depends:        
retpoline:      Y
name:           vboxguest
vermagic:       4.15.0-51-generic SMP mod_unload 

Now I can run the git commands without using sudo .现在我可以在不使用sudo情况下运行 git 命令。

if the check the permission of the contents, the permissions are okay:如果检查内容的权限,权限没问题:

They are, on the first level.他们是,在第一级。
But are they in .git/objects ?但是它们在.git/objects吗?

You might want to do, to be sure, a sudo chown -R vagrant:vagrant .git可以肯定的是,您可能想要执行sudo chown -R vagrant:vagrant .git

Add also the core.sharedRepository setting:还添加core.sharedRepository设置:

git config --global core.sharedRepository group

The OP Kakar mentions in the comments the hashicorp/vagrant issue 10913 , which states: OP Kakar 在评论中提到了hashicorp/vagrant问题 10913 ,其中指出:

I believe the bug is in the Guest Additions so you need to make sure the correct version of those are installed.我相信该错误存在于 Guest Additions 中,因此您需要确保安装了正确的版本。
Run modinfo vboxguest in Ubuntu to find out the version that is installed.在 Ubuntu 中运行modinfo vboxguest以找出安装的版本。

I appear to have solved this by updating my Virtualbox Guest Additions from 6.0.10 to 6.0.12, using dotless-de/vagrant-vbguest .我似乎通过使用dotless-de/vagrant-vbguest将我的 Virtualbox Guest Additions 从 6.0.10 更新到 6.0.12 来解决这个问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM