我执行以下步骤在DEBIAN Server上创建 1)git bare repo; 2)一个工作目录,在本地git push之后复制文件; 3)Windows上的本地克隆,克隆裸机服务器repo。
我执行了以下命令:
# SERVER: Setup git bare repo on server on Debian Wheezy v7.8, GIT 2.3.6
# mkdir /domains/site/test-workdir
# make a content copy on DEBIAN server into a test workdir
cp -rp /content/* /domains/site/test-workdir
mkdir /domains/git/site-bare.git
cd /domains/git/site-bare.git
git --git-dir=. --work-tree=/domains/site/test-workdir/. init
git config receive.denycurrentbranch ignore
cd /domains/git/site-bare.git/hooks
nano post-receive
# add the following content until # end
#!/bin/sh
export GIT_WORK_TREE=/domains/site/test-workdir/
export GIT_DIR=/domains/git/site-bare.git/
cd $GIT_DIR
git checkout -f
# end
chmod +x post-receive
cd ..
git add .
git commit -m "Initial commit"
git status
# On branch master
# nothing to commit, working directory clean
# LOCAL:
cd /w/Dev/\!GIT/
mkdir test-remote
cd /w/Dev/\!GIT/test-remote
git init
git remote add web-local ssh://root@192.168.1.101/domains/git/site-bare.git
git remote -v
# web-local ssh://root@192.168.1.101/domains/git/site-bare.git (fetch)
# web-local ssh://root@192.168.1.101/domains/git/site-bare.git (push)
git pull web-local master
# SERVER
cd /domains/site/test-workdir/
rm -r *
# LOCAL (Windows7 64bit, git v2.3.6)
# git push should execute post receive on remote, so workdir should get again the content
git push web-remote master
有一次我也得到了
Counting objects: 27, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (27/27), done.
Writing objects: 100% (27/27), 2.49 KiB | 0 bytes/s, done.
Total 27 (delta 21), reused 0 (delta 0)
remote: fatal: Not a git repository: '/domains/git/site-bare.git/.git'
To ssh://root@192.168.1.101/domains/git/site-bare.git
27b6ceb..8ed3301 master -> master
后来我没有得到这样的"不是git存储库"错误。 但无论如何,workdir没有内容,这是我的问题。
更新: 如果我做" git checkout -f"服务器,然后更新workdir,这意味着不会执行post-receive挂钩。
UPDATE2:修复了收发后的错误,但仍未更新。就好像我手动执行post-receive脚本一样。
知道为什么远程workdir没有更新?
答案 0 :(得分:0)
首先,您尝试手动执行的操作是Capistrano之类的工具,您应该查看它。
我认为你的问题是你跑了" git init"没有 - 裸露。如果你想要一个简单的回购,那么使用--bare,你就不会需要" git config receive.denycurrentbranch ignore"。
你应该看到这个相关的问题: How to copy a pushed branch to another directory?