2013-04-25 23 views
0

我有一個git倉庫,它具有dev,test和staging分支,這些分支被拉到服務器上的虛擬主機上。我需要能夠使用我的用戶帳戶來拉扯服務器,但是拉扯爲由www-data用戶(和組)擁有的文件。當我使用svn時,我可以sudo作爲www-data和svn更新--username --password選項,它將針對svn進行身份驗證,但保持正確的文件所有權。有沒有辦法用git來做到這一點(我實際上使用SSH密鑰而不是密碼進行身份驗證)。Git pull wih www-data permissions

+0

其實,在重新閱讀你的問題時,我不清楚。 *哪個*文件需要由該用戶和組擁有?版本控制下的'真正'文件,'.git'目錄下的Git文件,還是兩者都有?如果您試圖從Git存儲庫提供網站,則只需要「真實」文件即可擁有該用戶;如果您試圖共享存儲庫,或者允許通過HTTP訪問存儲庫,則需要Git的文件才能擁有該用戶。 – 2013-04-26 10:38:47

回答

2

你想設置存儲庫這個選項你拉進(摘自git help config):

core.sharedRepository 
     When group (or true), the repository is made shareable between several 
     users in a group (making sure all the files and objects are 
     group-writable). When all (or world or everybody), the repository will 
     be readable by all users, additionally to being group-shareable. When 
     umask (or false), git will use permissions reported by umask(2). When 
     0xxx, where 0xxx is an octal number, files in the repository will have 
     this mode value. 0xxx will override user’s umask value (whereas the 
     other options will only override requested parts of the user’s umask 
     value). Examples: 0660 will make the repo read/write-able for the 
     owner and group, but inaccessible to others (equivalent to group 
     unless umask is e.g. 0022). 0640 is a repository that is 
     group-readable but not group-writable. See git-init(1). False by 
     default. 

要設置這個選項,cd到需要有正確的組工作樹或庫/模式(而不是您想要從中取得的原始存儲庫),並運行git config core.sharedRepository group。它不僅爲存儲庫中的文件設置模式,還確保它們全部由擁有存儲庫根目錄的組擁有。無論您在存儲庫本地工作還是從其他存儲庫推入(例如通過git://協議),該選項都會生效。

如果您已經使用了錯誤的所有者和/或模式下沒有此選項集創建倉庫裏的文件,你需要先cd到庫中,並運行chmod -R g+rw .chgrp -R www-data .把它變成一個一致州。

+0

感謝您的回答。我這樣做的主要問題是我不能訪問git存儲庫本身,因爲它位於第三方基礎架構上。我正在考慮將這一切都轉移到GitHub上,但我不知道這是否會讓我的生活更輕鬆。 – 2013-04-26 10:24:44

+1

不要忘記,在Git中,每個工作副本都有自己的存儲庫:*存儲庫*並不意味着*上游*。您只需要存儲庫上的此設置即可擁有合適的組/模式。你**不需要做任何事情來源於你的原始資源庫。 – 2013-04-26 10:30:10