繁体   English   中英

在Git中跟踪文件权限。 运行git-cache-meta时出错:“发现:您有太多')'”

[英]Tracking file permissions in Git. Error running git-cache-meta: “find: you have too many ')'”

我目前正在尝试实施此建议 ,以便在执行Git克隆时能够保留文件权限。 但是,当我运行命令时,我收到此错误。

$ git-cache-meta.sh --store
find: you have too many ')'

先前的错误是关于Git列出的文件过多(我跟踪的文件大约有2.5GB,据我了解,这已经使单个Git项目的极限受到了限制)。

我对shell脚本的初始化做错了什么吗(我使用了此处列出的主要代码:

1.  #!/bin/sh -e
2.  
3.  #git-cache-meta -- simple file meta data caching and applying.
4.  #Simpler than etckeeper, metastore, setgitperms, etc.
5.  #from http://www.kerneltrap.org/mailarchive/git/2009/1/9/4654694
6.  #modified by n1k
7.  # - save all files metadata not only from other users
8.  # - save numeric uid and gid
9.
10. # 2012-03-05 - added filetime, andris9
11.
12. : ${GIT_CACHE_META_FILE=.git_cache_meta}
13. case $@ in
14. --store|--stdout)
15. case $1 in --store) exec > $GIT_CACHE_META_FILE; esac
16. find $(git ls-files)\
17.     \( -printf 'chown %U %p\n' \) \
18.     \( -printf 'chgrp %G %p\n' \) \
19.     \( -printf 'touch -c -d "%AY-%Am-%Ad %AH:%AM:%AS" %p\n' \) \
20.     \( -printf 'chmod %#m %p\n' \) ;;
21. --apply) sh -e $GIT_CACHE_META_FILE;;
22. *) 1>&2 echo "Usage: $0 --store|--stdout|--apply"; exit 1;;
23. esac

但我没有使用任何修订版,这些修订版似乎正在解决单独的问题)。 该页面上报告的一些错误似乎与文件名中的特定字符有关,但从头到尾,我找不到任何可能引起错误的'('或')'。

但是,如果与尝试跟踪太多文件有关,那么是否有任何建议在将文件部署到Git时维护文件权限和所有者元数据?

尝试这个:

function get_metadata {
    git ls-files | 
    xargs stat -c $'%a\t%U\t%G\t%x\t%n' | 
    while IFS=$'\t' read -r perm user grp date name; do 
        echo chown "$user" "$name"
        echo chgrp "$grp" "$name"
        echo chmod "$perm" "$name"
        echo touch -c -d "'$date'" "$name"
    done
}

case $1 in
    --stdout) get_metadata ;;
    --store)  get_metadata > "$GIT_CACHE_META_FILE" ;;
    --apply)
        [[ -f "$GIT_CACHE_META_FILE" ]] &&
        sh "$GIT_CACHE_META_FILE"
        ;;
    *) echo "usage: ..." ;;
esac

假设您的文件名都不包含换行符。

暂无
暂无

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

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