2012-06-18 127 views
1

我有一個裸回購,我直接編輯文件,沒有做一個git commit -a -m命令,因爲我匆忙,是否有可能更新git知道我所做的更改?因爲當我在裸露的回購做git status我得到一個:更新裸回購文件git

fatal: This operation must be run in a work tree 

編輯:這是我的裸回購操作:

#!/bin/bash 
NAME=$1 

mkdir git/$1 
cd git/$1 
git init --bare 
echo "git clone /root/git/$1 /tmp/git/$1" >> hooks/post-receive 
echo "cp -rp /tmp/git/$1/* /var/www/$1" >> hooks/post-receive 
echo "rm -rf /tmp/git/$1" >> hooks/post-receive 

所以我做了什麼直接的是編輯文件在/var/www/$1/目錄。

+0

你從git-stash中得到什麼?我以前一直陷入這個陷阱,但最終從別處重新克隆。 –

+7

你直接編輯了哪些文件?裸回購沒有工作副本。 –

+0

我更新了問題,請重新打開該問題。 – Michelle

回答

0

好吧,我想你基本上可以做什麼post-receive掛鉤是做反向(未經測試):

git clone /root/git/<repo> /tmp/<tmprepo> 
cp -rp /var/www/* /tmp/<tmprepo> 
cd /tmp/<tmprepo> 
git checkout <branch_to_put_cruft_on> 
git commit -a -m "collecting misc edits from web tree" 
git push origin <branch_to_put_cruft_on> 
cd - 
rm -rf /tmp/<tmprepo> 

如果有/var/www其他文件超出與回購的東西,在cp漁獲更多超過需要,但git commit -a應忽略當前未被跟蹤的文件。

你也許還與git小號--git-dir--work-tree選項做到這一點,這可能會給一個清晰的解決方案,但我不能與那些發揮廣泛。這些方針的東西(也未經測試,情況因人而異,等等,等等...):

git clone /root/git/<repo> /tmp/<tmprepo> 
cd /tmp/<tmprepo> 
git checkout <somebranch> 
git --git-dir=/tmp/<tmprepo>/.git --work-tree=/var/www commit -a -m "collect edits" 
git push origin <somebranch> 
cd - 
rm -rf /tmp/<tmprepo> 

要更加小心,而不是做git commit -a,使用--git-dir--work-tree選項與適當的系列git add S和做一個適當的承諾。