如何将文件权限恢复为“认为”文件应该是? [英] How to recover the file permissions to what git "thinks" the file should be?

查看:140
本文介绍了如何将文件权限恢复为“认为”文件应该是?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个git结帐。所有的文件权限都不同于git认为它们应该是因为它们都显示为修改。



不触摸文件的内容(只是想修改权限)如何将所有文件权限设置为git认为应该是什么?

解决方案

Git跟踪文件授权并公开权限使用 git diff -p 创建修补程序时更改。所以我们需要的是:


  1. 创建反向补丁

  2. 仅包含权限更改

  3. 将补丁应用到我们的工作副本

作为单行:

  git diff -p -R --no-color \ 
| grep -E^(diff |(old | new)mode)--color = never \
| git apply

您还可以将其添加为您的git配置的别名...

  git config --global --add alias.permission-reset'!git diff -p -R --no-color | grep -E^(diff |(old | new)mode)--color = never | git申请'

...您可以通过以下方式调用:

  git permission-reset 

注意如果您的shell是 bash ,请确保使用'而不是引用!git 引用,否则它将替换为您运行的最后一个 git 命令。 p>

Thx to @Mixologic通过简单地使用 -R git diff ,不再需要繁琐的 sed 命令。


I have a git checkout. All the file permissions are different than what git thinks they should be therefore they all show up as modified.

Without touching the content of the files (just want to modify the permissions) how do I set all the files permissions to what git thinks they should be?

解决方案

Git keeps track of filepermission and exposes permission changes when creating patches using git diff -p. So all we need is:

  1. create a reverse patch
  2. include only the permission changes
  3. apply the patch to our working copy

As a one-liner:

git diff -p -R --no-color \
    | grep -E "^(diff|(old|new) mode)" --color=never  \
    | git apply

you can also add it as an alias to your git config...

git config --global --add alias.permission-reset '!git diff -p -R --no-color | grep -E "^(diff|(old|new) mode)" --color=never | git apply'

...and you can invoke it via:

git permission-reset

Note, if you shell is bash, make sure to use ' instead of " quotes around the !git, otherwise it gets substituted with the last git command you ran.

Thx to @Mixologic for pointing out that by simply using -R on git diff, the cumbersome sed command is no longer required.

这篇关于如何将文件权限恢复为“认为”文件应该是?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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