[英]Updating bare repo files to git
I have a bare repo and I edited the files directly without doing a git commit -a -m
command because I was rushing, is it possible to update the git to know the changes I have made? 我有一个裸露的回购协议,因为我在赶时间,所以我不做git commit -a -m
命令就直接编辑了文件,是否有可能更新git以了解我所做的更改? Because when I do a git status
on the bare repo I get a: 因为当我在裸仓库上执行git status
时,我得到一个:
fatal: This operation must be run in a work tree
EDIT: This is what I do for the bare repo: 编辑:这就是我为裸仓库做的事情:
#!/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
So what I did was edit directly the files at /var/www/$1/
directory. 因此,我要做的是直接编辑/var/www/$1/
目录中的文件。
Well, I suppose you could do essentially the reverse of what that post-receive
hook is doing (untested): 好吧,我想您基本上可以执行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>
If there are additional files in /var/www
beyond the stuff from the repo, the cp
catches more than necessary, but the git commit -a
should ignore files that are not currently being tracked. 如果/var/www
除了回购中的内容以外还有其他文件,则cp
捕获的内容超出了必要,但是git commit -a
应该忽略当前未跟踪的文件。
You could probably also accomplish this with git
s --git-dir
and --work-tree
options, and that might give a cleaner solution, but I've not played with those extensively. 您可能还可以使用git
s --git-dir
和--work-tree
选项来完成此操作,这可能会提供更--work-tree
解决方案,但我并未广泛使用它们。 Something along these lines (also untested, YMMV, blah, blah...): 遵循以下原则(也未经测试,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>
To be even more careful, rather than doing git commit -a
, use the --git-dir
and --work-tree
options with the appropriate series of git add
s and do a proper commit. 要更加小心,而不是执行git commit -a
,请使用--git-dir
和--work-tree
选项以及适当的一系列git add
s并进行适当的提交。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.