[英]Updating bare repo files to 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/
目錄中的文件。
好吧,我想您基本上可以執行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
s --git-dir
和--work-tree
選項來完成此操作,這可能會提供更--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
s並進行適當的提交。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.