3 回答

TA貢獻1824條經驗 獲得超8個贊
將git-cache-meta在SO問題中提到“ 混帳-如何恢復文件權限的Git認為文件應 ”(和git的FAQ)是更staightforward方法。
這個想法是在.git_cache_meta文件中存儲文件和目錄的權限。
它是一個單獨的文件,沒有在Git倉庫中直接版本化。
這就是為什么它的用法是:
$ git bundle create mybundle.bdl master; git-cache-meta --store
$ scp mybundle.bdl .git_cache_meta machine2:
#then on machine2:
$ git init; git pull mybundle.bdl master; git-cache-meta --apply
那么你:
捆綁您的倉庫并保存相關的文件權限。
將這兩個文件復制到遠程服務器上
恢復那里的倉庫,并申請權限

TA貢獻1815條經驗 獲得超6個贊
Git是為軟件開發而創建的版本控制系統,因此從整個模式和權限集中它只存儲可執行位(對于普通文件)和符號鏈接位。如果要存儲完整權限,則需要第三方工具,如git-cache-meta(由VonC提及)或Metastore(由etckeeper使用)?;蛘吣梢允褂肐siSetup,IIRC使用git作為后端。
請參閱Git Wiki上的界面,前端和工具頁面。

TA貢獻1853條經驗 獲得超6個贊
這已經很晚了,但可能對其他人有所幫助。我通過向我的存儲庫添加兩個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
> $DATABASE
echo -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` >> $DATABASE
done
for 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` >> $DATABASE
done
IFS=$IFS_OLD
# Add the permissions database file to the index
git add $DATABASE -f
echo "OK"
git的/鉤/結賬后:
#!/bin/bash
SELF_DIR=`git rev-parse --show-toplevel`
DATABASE=$SELF_DIR/.permissions
echo -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 $ITEM
done < $DATABASE
IFS=$IFS_OLD
echo "OK"
exit 0
第一個鉤子在您“提交”時被調用,并將讀取存儲庫中所有文件的所有權和權限,并將它們存儲在名為.permissions的存儲庫根目錄中的文件中,然后將.permissions文件添加到提交中。
當您“結帳”時將調用第二個掛鉤,并將瀏覽.permissions文件中的文件列表并恢復這些文件的所有權和權限。
您可能需要使用sudo進行提交和簽出。
確保預提交和結帳后腳本具有執行權限。
- 3 回答
- 0 關注
- 1412 瀏覽
添加回答
舉報