【问题标题】:Git always pulls files that I cant editGit总是拉出我无法编辑的文件
【发布时间】:2012-05-26 07:35:24
【问题描述】:

当我使用终端在 OSX 上下载文件时,默认情况下我没有编辑权限。
我该如何改变呢?


kirkstrobeck:atheycreek kirkstrobeck$ ls -lad ~ . .git
drwxrwxrwx   8 kirkstrobeck  staff   272 May 24 18:20 .
drwxrwxrwx  16 kirkstrobeck  staff   544 May 25 10:58 .git
drwxr-xr-x+ 92 kirkstrobeck  staff  3128 May 24 15:17 /Users/kirkstrobeck

kirkstrobeck:~ kirkstrobeck$ umask
0022

kirkstrobeck:atheycreek kirkstrobeck$ ls -l
total 8
-rwxrwxrwx  1 kirkstrobeck  staff  2143 Mar  6 14:49 README.md
drwxrwxrwx  4 kirkstrobeck  staff   136 May 23 14:45 www
kirkstrobeck:atheycreek kirkstrobeck$ 

注意:我在用 CHMOD 修复问题后运行了这些终端命令,但我每次都这样做,因为它会拉下错误的权限。

【问题讨论】:

  • 我经常只是使用git pull
  • 你在哪个目录?文件权限是什么样的?您可以使用ls -l 来查看文件权限。
  • 就像@torek 提到的,如果你的umask 是022,那么我能想到的唯一解释是你没有文件/目录的适当权限/所有权,你能做到@987654327 @检查?
  • 请向我们展示ls -lad ~ . .git 的输出,以便比较您的主目录、工作区目录和.git 目录的权限。
  • 不要忘记 - 在您更改权限后提交并推送到 repo 或服务器。

标签: git


【解决方案1】:

尝试检查 core.sharedRepository 这可以设置,因此 umask 不是权限的默认值:

来自 git-config(1):

当 group(或 true)时,存储库可在组中的多个用户之间共享(确保所有文件和对象都是组可写的)。当所有(或世界或所有人)时,所有用户都可以读取存储库,此外还可以组共享。当 umask(或 false)时,git 将使用 umask(2) 报告的权限。当 0xxx(其中 0xxx 是八进制数)时,存储库中的文件将具有此模式值。 0xxx 将覆盖用户的 umask 值(而其他选项只会覆盖用户的 umask 值的请求部分)。示例:0660 将使所有者和组可以读/写 repo,但其他人无法访问(相当于组,除非 umask 是例如 0022)。 0640 是组可读但不可组写的存储库。请参阅 git-init(1)。默认为假。

所以

git config core.sharedRepository all

会反过来让每个人都可以访问。

【讨论】:

    【解决方案2】:

    当你说你没有编辑权限时——你到底是什么意思?

    注意:我在使用 CHMOD 修复问题后运行了这些终端命令

    这意味着输出没有帮助。所有这些权限显示:

    kirkstrobeck:atheycreek kirkstrobeck$ ls -lad ~ . .git
    drwxrwxrwx   8 kirkstrobeck  staff   272 May 24 18:20 .
    drwxrwxrwx  16 kirkstrobeck  staff   544 May 25 10:58 .git
    drwxr-xr-x+ 92 kirkstrobeck  staff  3128 May 24 15:17 /Users/kirkstrobeck
    

    是否对列出的所有内容都具有编辑权限 - 如果您之前在文件夹上运行过 chmod -R 777 .,这是可以预料的。

    更相关的权限是您尝试编辑的文件和文件夹的权限。通过一个特定的命令示例,它产生的错误和相关文件的权限 - 将得到一个具体的答案,如果没有这个,一些有根据的猜测工作:

    写权限不是 git 问题

    Git 根本不存储文件夹,只存储文件的可执行权限。您可以通过以下方式向自己展示这一点:

    [andy@work:/tmp/so/original]$ git init
    [andy@work:/tmp/so/original]$ touch 0700
    [andy@work:/tmp/so/original]$ touch 0600
    [andy@work:/tmp/so/original]$ touch 0500
    [andy@work:/tmp/so/original]$ touch 0400
    [andy@work:/tmp/so/original]$ chmod 0700 0700
    [andy@work:/tmp/so/original]$ chmod 0600 0600
    [andy@work:/tmp/so/original]$ chmod 0500 0500
    [andy@work:/tmp/so/original]$ chmod 0400 0400
    [andy@work:/tmp/so/original]$ git add *
    [andy@work:/tmp/so/original]$ git commit -va
    [master (root-commit) a304e1b] adding files with the named permissions
    0 files changed
    create mode 100644 0400
    create mode 100755 0500
    create mode 100644 0600
    create mode 100755 0700
    [andy@work:/tmp/so/original(master)]$ ls -la 
    total 12
    drwxr-xr-x 3 andy users 4096 May 28 14:51 .
    drwxr-xr-x 3 andy users 4096 May 28 14:48 ..
    -r-------- 1 andy users    0 May 28 14:48 0400
    -r-x------ 1 andy users    0 May 28 14:48 0500
    -rw------- 1 andy users    0 May 28 14:48 0600
    -rwx------ 1 andy users    0 May 28 14:48 0700
    drwxr-xr-x 8 andy users 4096 May 28 14:51 .git
    

    上面显示(使用ls -la)文件权限,以数字(文件名)和读、写、可执行权限(在左侧)表示。只有0500和0700这两个文件有可执行权限。

    [andy@work:/tmp/so/checkout]$ git init
    Initialized empty Git repository in /tmp/so/checkout/.git/
    [andy@work:/tmp/so/checkout]$ git pull ../original/
    remote: Counting objects: 3, done.
    remote: Compressing objects: 100% (2/2), done.
    remote: Total 3 (delta 0), reused 0 (delta 0)
    Unpacking objects: 100% (3/3), done.
    From ../original
    * branch            HEAD       -> FETCH_HEAD
    [andy@work:/tmp/so/checkout(master)]$ ls -la 
    total 12
    drwxr-xr-x 3 andy users 4096 May 28 14:52 .
    drwxr-xr-x 4 andy users 4096 May 28 14:52 ..
    -rw-r--r-- 1 andy users    0 May 28 14:52 0400
    -rwxr-xr-x 1 andy users    0 May 28 14:52 0500
    -rw-r--r-- 1 andy users    0 May 28 14:52 0600
    -rwxr-xr-x 1 andy users    0 May 28 14:52 0700
    drwxr-xr-x 8 andy users 4096 May 28 14:52 .git
    [andy@work:/tmp/so/checkout(master)]$
    

    以上表明 checkout 具有默认文件权限(由umask 指定),如果提交为可执行文件,则添加可执行文件。

    了解以上内容应该有助于您专注于真正的问题所在。

    修复文件权限

    如果您的结帐权限错误,您可以使用如下命令修复它们:

    # make sure all files are owned by you
    sudo chmod -R andy:users .
    # reset to default permissions
    sudo find . -type d -exec chmod 0755 {} \; -or -type f -exec chmod 0644 {} \;
    

    仔细检查您收到的任何错误消息中提到的文件;该文件的权限现在是0644,它所在的文件夹是0755。

    修正文件权限后,您应该可以开始了。

    请注意,您需要对文件夹的可执行权限才能查找和操作其中的内容。如果您在文件夹上没有可执行权限,则在其中执行几乎任何操作都会出现权限错误。 但是,git根本不存储文件夹,如果这是问题的话,它与git无关。

    如果这对您的 repo 进行了任何更改,您可以提交它们:

    git commit -am "Resetting file permissions to their default values"
    

    这只会提交对文件的可执行属性的更改,并且只是一个清理步骤 - 不会修复任何会导致其他人检查 repo 的权限问题。

    忽略文件权限

    如果您希望您的结帐完全忽略您应用于结帐的权限,您可以使用:

    git config core.fileMode false
    

    通过这种方式,git 不会将您应用于结帐的文件权限更改视为提交更改 - 但鉴于可用信息,这不太可能相关。

    【讨论】:

      【解决方案3】:

      git 根据您的 umask 设置工作。 git 操作的唯一工作目录权限是执行位。如果您不会写,您必须将您的umask 设置为非常严格,例如,0277 将为您自己删除w,为群组和其他人删除rwx

      尝试运行umask 以查看您当前的设置,并尝试运行umask 022 设置典型设置(022 = 删除w 用于组和其他)。

      【讨论】:

      • 那有点莫名其妙......它对我来说“只是工作”。如果我摆弄我的 umask,新创建的文件(在任何 git pull 或 git checkout 上)将获得适当的权限。
      猜你喜欢
      • 1970-01-01
      • 2015-07-31
      • 2020-03-15
      • 2023-04-03
      • 2017-12-27
      • 1970-01-01
      • 2016-08-22
      • 1970-01-01
      • 2023-03-18
      相关资源
      最近更新 更多