将裸仓库文件更新为git

时间:2012-06-18 04:07:20

标签: git

我有一个裸仓库,我直接编辑了文件而没有执行git commit -a -m命令,因为我很急,是否可以更新git以了解我所做的更改?因为当我在裸仓库上做git status时,我得到了:

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/目录下的文件。

1 个答案:

答案 0 :(得分: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应忽略当前未被跟踪的文件。< / p>

您也可以使用git s --git-dir--work-tree选项完成此操作,这可能会提供更清晰的解决方案,但我并没有广泛使用它们。沿着这些方向的东西(也未经测试,YMMV,等等,等等......):

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的相应系列一起使用,并进行适当的提交。< / p>