如何通过post-receive上传我的文件?

时间:2015-03-14 12:52:03

标签: git git-post-receive

我有以下shell脚本作为post-receive钩子,它应该将我的工作副本复制到我的/mnt/repo/文件夹中:

#!/bin/sh
rm -rf /tmp/repo/
rm -rf /mnt/repo/*

mkdir /tmp/repo/ && cd /tmp/repo/

git init
git remote add origin file:///home/git/repos/repo.git
git fetch
git checkout development

cp -r /tmp/repo/* /mnt/repo/

如果我在本地运行它,它可以正常工作。但是,如果它在推送后由Git运行,它将无法工作,我在我的本地Git Bash中得到以下输出:

$ git push local development
git@192.168.178.88's password:
Counting objects: 6, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (3/3), done.
Writing objects: 100% (3/3), 349 bytes | 0 bytes/s, done.
Total 3 (delta 2), reused 0 (delta 0)
remote: Initialized empty Git repository in /tmp/repo/
remote: From file:///home/git/repos/repo
remote:  * [new branch]      development -> origin/development
remote:  * [new branch]      release    -> origin/release
remote: fatal: This operation must be run in a work tree
To git@192.168.178.88:repos/repo.git
   01568cc..ee31229  development -> development

此外,在我的/tmp/repo/mnt/repo文件夹中,我有以下文件夹结构:

drwxr-xr-x  7 git  git  220 Mar 14 13:47 .
drwxrwxrwt  3 root root  60 Mar 14 13:47 ..
drwxr-xr-x  2 git  git   40 Mar 14 13:47 branches
-rw-r--r--  1 git  git  183 Mar 14 13:47 config
-rw-r--r--  1 git  git   73 Mar 14 13:47 description
-rw-r--r--  1 git  git  240 Mar 14 13:47 FETCH_HEAD
-rw-r--r--  1 git  git   23 Mar 14 13:47 HEAD
drwxr-xr-x  2 git  git  200 Mar 14 13:47 hooks
drwxr-xr-x  2 git  git   60 Mar 14 13:47 info
drwxr-xr-x 44 git  git  880 Mar 14 13:47 objects
drwxr-xr-x  5 git  git  100 Mar 14 13:47 refs

1 个答案:

答案 0 :(得分:1)

这是一个新的存储库,因此尚未附加工作树。

Read here了解详情。