如何使用 post-receive 上传我的文件?
How do I get my files uploaded with 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/
如果我 运行 在本地,它工作得很好。但是,如果是运行 by Git push后,就不行了,我在本地得到如下输出 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
这是一个新的存储库,因此尚未将工作树附加到它。
Read here了解更多详情。
我有以下 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/
如果我 运行 在本地,它工作得很好。但是,如果是运行 by Git push后,就不行了,我在本地得到如下输出 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
这是一个新的存储库,因此尚未将工作树附加到它。
Read here了解更多详情。