我已经设置了一个简单的服务器,其中包含一个 git 帐户,我使用 SSH 连接到该帐户。
我尝试使用 git clone ssh://git@server:port/repository
克隆位于其主目录 (/srv/git) 中的存储库。除非我在存储库名称前加上 ~/
否则它不会工作。
如果我不预先添加它,它只会在存储库位于文件系统的根目录时起作用。
不知何故,git 没有实现自己的用户目录。我怎样才能改变这种“奇怪”的行为,使其按预期工作? (至少对我而言)
最佳答案
您必须提供绝对路径或使用 ~
指示主目录的路径。引自 git-clone(1)
:
The ssh and git protocols additionally support ~username expansion:
ssh://[user@]host.xz[:port]/~[user]/path/to/repo.git/
git://host.xz[:port]/~[user]/path/to/repo.git/
[user@]host.xz:/~[user]/path/to/repo.git/
另一种解决方案是使用诸如 gitolite 之类的东西.然后您将能够使用存储库 URL,例如 sshuser@host:reponame
关于git - 通过 SSH 克隆让服务器认为 GIT 的主目录是文件系统的根目录?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12311440/