3 回答

TA貢獻(xiàn)1824條經(jīng)驗 獲得超8個贊
將git-cache-meta在SO問題中提到“ 混帳-如何恢復(fù)文件權(quán)限的Git認(rèn)為文件應(yīng) ”(和git的FAQ)是更staightforward方法。
這個想法是在.git_cache_meta文件中存儲文件和目錄的權(quán)限。
它是一個單獨的文件,沒有在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
那么你:
捆綁您的倉庫并保存相關(guān)的文件權(quán)限。
將這兩個文件復(fù)制到遠(yuǎn)程服務(wù)器上
恢復(fù)那里的倉庫,并申請權(quán)限

TA貢獻(xiàn)1815條經(jīng)驗 獲得超6個贊
Git是為軟件開發(fā)而創(chuàng)建的版本控制系統(tǒng),因此從整個模式和權(quán)限集中它只存儲可執(zhí)行位(對于普通文件)和符號鏈接位。如果要存儲完整權(quán)限,則需要第三方工具,如git-cache-meta(由VonC提及)或Metastore(由etckeeper使用)。或者您可以使用IsiSetup,IIRC使用git作為后端。
請參閱Git Wiki上的界面,前端和工具頁面。

TA貢獻(xiàn)1853條經(jīng)驗 獲得超6個贊
這已經(jīng)很晚了,但可能對其他人有所幫助。我通過向我的存儲庫添加兩個git鉤子來做你想做的事情。
的.git /鉤/預(yù)提交:
#!/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的/鉤/結(jié)賬后:
#!/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
第一個鉤子在您“提交”時被調(diào)用,并將讀取存儲庫中所有文件的所有權(quán)和權(quán)限,并將它們存儲在名為.permissions的存儲庫根目錄中的文件中,然后將.permissions文件添加到提交中。
當(dāng)您“結(jié)帳”時將調(diào)用第二個掛鉤,并將瀏覽.permissions文件中的文件列表并恢復(fù)這些文件的所有權(quán)和權(quán)限。
您可能需要使用sudo進行提交和簽出。
確保預(yù)提交和結(jié)帳后腳本具有執(zhí)行權(quán)限。
添加回答
舉報