1

我通过 ssh 创建了一个 git 存储库。它可以工作,但我看不到目录中的文件。

远程(SSH):

mkdir test.com
cd test.com
git init

client(git bash)
cd /apache/htdocs
git clone git://myserverip/test.com
cd test.com
git add --all .
git commit -a -m "first"
git push origin master
4

3 回答 3

2

我认为,您必须在服务器上的存储库中添加文件并提交。为什么你不尝试裸存储库?

如果您需要通过远程推送提交,请尝试以下命令:

在服务器上创建存储库:

cd /usr/local/git/    ## or your own repo destination
mkdir repo.git
cd repo.git
git init
touch README
git add .
git commit -a -m "start my repository"

在客户端(例如 ubuntu)上:

git clone ssh://User@serverip:sshport/usr/local/git/repo.git myrepo
cd myrepo
git branch someUser   # create new branch
vim README   ## some change on the file
git add README
git commit -a -m "some change by someUser"    ## user commit changes
git push origin someUser   ## push commit to server

用户推送更改后的系统管理员必须合并提交,简单的方法是:

cd /usr/local/git/repo.git
git merge someUser   ##  merge repo by user commit
于 2012-05-20T08:17:53.930 回答
1

将文件推送到远程存储库不会更新文件树(“索引”)。它更新对象的存储。

要更新树以反映存储的对象,您必须git reset --hard在该远程存储库中执行操作以将其更新为新的HEAD.

这是一件坏事,因此远程存储库通常设置为“裸”:一种用于 git 托管的特殊存储库格式,它没有工作树(以及其他区别:例如没有.git目录:配置文件更方便存储在其根目录中)。

为您的上游使用裸存储库:git init --bare.

于 2012-05-19T23:14:49.847 回答
1

我找到了解决方案

mkdir test.com
cd test.com
git init
cd .git
cd hooks
vi post-receive
chmod +x post-receive

接收后

#!/bin/sh
cd ..
env -i git reset --hard
于 2012-05-31T21:11:07.320 回答