Git总是拉取我不能编辑的文件 [英] Git always pulls files that I cant edit

查看:104
本文介绍了Git总是拉取我不能编辑的文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我用终端在OSX上下载文件时,默认情况下我没有编辑权限。

如何更改它?




  kirkstrobeck:atheycreek kirkstrobeck $ ls -lad〜。 .git 
drwxrwxrwx 8 kirkstrobeck staff 272 5月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 
共8
-rwxrwxrwx 1 kirkstrobeck员工2143 3月6日14:49 README.md
drwxrwxrwx 4 kirkstrobeck员工136 5月23日14:45 www
kirkstrobeck: atheycreek kirkstrobeck






注意:我运行了这些终端命令在解决CHMOD问题后,我每次都这么做,因为它会拖拽错误的烫发。

当你说你没有编辑权限 - 你究竟是什么意思?


注意:在解决CHMOD


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

  kirkstrobeck:atheycreek kirkstrobeck $ ls -lad〜。 .git 
drwxrwxrwx 8 kirkstrobeck staff 272 5月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

是你的 do 具有所有列出的编辑权限 - 如果你以前运行过 chmod -R 777。在文件夹中。



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

写perms不是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 /原始] $ chmod 0400 0400
[andy @ work:/ tmp / so / original] $ git add *
[andy @ work:/ tmp / so / original] $ git commit -va
[master(root-commit)a304e1b]添加具有命名权限的文件
0文件已更改
创建模式100644 0400
创建模式100755 0500
创建模式100644 0600
创建模式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
-rx ------ 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 )文件许可以数字(文件名)和读,写,可执行许可在左边)。

  [andy @ work:/ tmp / so / checkout] $ git init 
在/tmp/so/checkout/.git/
中初始化了空的Git仓库[andy @ work:/ tmp / so / checkout] $ git pull ../original/
remote:Counting对象:3,完成。
remote:压缩对象:100%(2/2),完成。
remote:合计3(delta 0),重用0(delta 0)
解包对象:100%(3/3),完成。
从../original
*分支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用户4096 May 28 14:52 ..
-rw-r - r-- 1 andy users 0 5月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)] $

以上显示结帐有默认文件权限(由 umask

了解上述内容可以帮助您专注于真正问题所在。



修复文件权限



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

 #确保所有文件都由您拥有
sudo chmod -R andy:users。
#重置为默认权限
sudo查找。 -type d -exec chmod 0755 {} \; -or -type f -exec chmod 0644 {} \;

仔细检查您提供的错误消息中提到的文件;



在更正文件权限的情况下,您应该很好。



请注意,您需要文件夹 上的可执行权限才能找到并处理内容。如果您在文件夹中没有可执行文件夹,您会收到执行其中几乎任何内容的权限错误。 然而,git根本不存储文件夹,如果这是问题,它不是git相关的。

如果做了任何更改您可以将它们提交给它们:

  git commit -am将文件权限重置为默认值

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



忽略文件权限



如果您想要结账要完全忽略你应用于结账的权限,你可以使用:

  git config core.fileMode false 

code>

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

When I pull files down on OSX with terminal, I don't have edit permissions by default.
How can I change that?


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$ 


Note: I ran these terminal commands after fixing the issue with CHMOD, but I do that every time, because it pulls down the wrong perms.

解决方案

When you say you don't have edit permissions - what exactly do you mean?

Note: I ran these terminal commands after fixing the issue with CHMOD

That means the output isn't helpful. All these permissions show:

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

is that you do have edit permissions for everything listed - to be expected if you've previously ran chmod -R 777 . on the folder.

The more relevant permissions are those of the file and folder for the things you're trying to edit. With a specific example of a command, the errors it generated and the permissions of relevant files - would come a specific answer, in the absence of that, some educated guess work:

Write perms aren't a git problem

Git doesn't store folders at all, and only stores the executable permission for files. you can demonstrate this to yourself with something like this:

[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

The above shows (with ls -la) file permissions indicated as both numbers (the filenames) and read, write, executable perms (on the left). Only the two files 0500 and 0700 have executable permissions.

[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)]$

The above indicates that the checkout has default file permissions (those dictated by umask) with the addition of being executable if committed as executable.

Knowing the above should help you focus on where the real problem lies.

Fixing file permissions

If your checkout has wrong permissions, you can fix them with a command like this:

# 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 {} \;

Double check that for files mentioned in whatever error message you have; the permissions of the file are now 0644, and the folder it's in are 0755.

With file permissions corrected, you should be good to go.

Note that you need executable permissions on folders to be able to find and manipulate the contents. If you don't have executable perms on a folder you'll get permission errors doing almost anything within it. But, again, git doesn't store folders at all, it's not git-related if that's the problem.

If that made any changes to your repo you can commit them with:

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

That'll only be committing changes to the executable property of files, and is just a cleanup step - not fixing anything which would cause permission issues to someone else checking out the repo.

Ignoring file permissions

If you want your checkout to entirely ignore permissions you apply to your checkout, you can use:

git config core.fileMode false

in this way git won't consider file-permission changes you apply to your checkout as changes to commit - but that's not likely to be relevant given the information available.

这篇关于Git总是拉取我不能编辑的文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆