墨色风雨
这已经很晚了,但可能对其他人有所帮助。我通过向我的存储库添加两个git钩子来做你想做的事情。的.git /钩/预提交:#!/bin/bash## A hook script called by "git commit" with no arguments. The hook should# exit with non-zero status after issuing an appropriate message if it wants# to stop the commit.SELF_DIR=`git rev-parse --show-toplevel`DATABASE=$SELF_DIR/.permissions# Clear the permissions database file> $DATABASEecho -n "Backing-up permissions..."IFS_OLD=$IFS; IFS=$'\n'for FILE in `git ls-files --full-name`do # Save the permissions of all the files in the index echo $FILE";"`stat -c "%a;%U;%G" $FILE` >> $DATABASEdonefor DIRECTORY in `git ls-files --full-name | xargs -n 1 dirname | uniq`do # Save the permissions of all the directories in the index echo $DIRECTORY";"`stat -c "%a;%U;%G" $DIRECTORY` >> $DATABASEdoneIFS=$IFS_OLD# Add the permissions database file to the indexgit add $DATABASE -fecho "OK"git的/钩/结账后:#!/bin/bashSELF_DIR=`git rev-parse --show-toplevel`DATABASE=$SELF_DIR/.permissionsecho -n "Restoring permissions..."IFS_OLD=$IFS; IFS=$'\n'while read -r LINE || [[ -n "$LINE" ]];do ITEM=`echo $LINE | cut -d ";" -f 1` PERMISSIONS=`echo $LINE | cut -d ";" -f 2` USER=`echo $LINE | cut -d ";" -f 3` GROUP=`echo $LINE | cut -d ";" -f 4` # Set the file/directory permissions chmod $PERMISSIONS $ITEM # Set the file/directory owner and groups chown $USER:$GROUP $ITEMdone < $DATABASEIFS=$IFS_OLDecho "OK"exit 0第一个钩子在您“提交”时被调用,并将读取存储库中所有文件的所有权和权限,并将它们存储在名为.permissions的存储库根目录中的文件中,然后将.permissions文件添加到提交中。当您“结帐”时将调用第二个挂钩,并将浏览.permissions文件中的文件列表并恢复这些文件的所有权和权限。您可能需要使用sudo进行提交和签出。确保预提交和结帐后脚本具有执行权限。