2012-06-18 129 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和做一个适当的承诺。