VPS上的Git远程存储库接受推送而不是创建文件?

时间:2014-04-08 00:54:05

标签: git ssh repository vps

我正在使用Digital Ocean VPS,获得了Ubuntu Server 12.0.4,并尝试按照Digital Ocean的一些说明进行操作并且直截了当。

但是,一旦我从笔记本电脑上推出,我就会收到VPS的回复:

Counting objects: 4, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (3/3), done.
Writing objects: 100% (3/3), 335 bytes, done.
Total 3 (delta 0), reused 0 (delta 0)
remote: usage: git [--version] [--exec-path[=<path>]] [--html-path] [--man-path] [--info-path]
remote:            [-p|--paginate|--no-pager] [--no-replace-objects] [--bare]
remote:            [--git-dir=<path>] [--work-tree=<path>] [--namespace=<name>]
remote:            [-c name=value] [--help]
remote:            <command> [<args>]
remote: 
remote: The most commonly used git commands are:
remote:    add        Add file contents to the index
remote:    bisect     Find by binary search the change that introduced a bug
remote:    branch     List, create, or delete branches
remote:    checkout   Checkout a branch or paths to the working tree
remote:    clone      Clone a repository into a new directory
remote:    commit     Record changes to the repository
remote:    diff       Show changes between commits, commit and working tree, etc
remote:    fetch      Download objects and refs from another repository
remote:    grep       Print lines matching a pattern
remote:    init       Create an empty git repository or reinitialize an existing one
remote:    log        Show commit logs
remote:    merge      Join two or more development histories together
remote:    mv         Move or rename a file, a directory, or a symlink
remote:    pull       Fetch from and merge with another repository or a local branch
remote:    push       Update remote refs along with associated objects
remote:    rebase     Forward-port local commits to the updated upstream head
remote:    reset      Reset current HEAD to the specified state
remote:    rm         Remove files from the working tree and from the index
remote:    show       Show various types of objects
remote:    status     Show the working tree status
remote:    tag        Create, list, delete or verify a tag object signed with GPG
remote: 
remote: See 'git help <command>' for more information on a specific command.
remote: hooks/post-receive: 3: hooks/post-receive: checkout: not found
To ssh://root@ip.my.vps.address/gits/cleu/cleu.git
   b21f9df..8eb93e0  master -> master

在VPS上我得到了:

/gits/cleu.git/

并且/gits/cleu.git/hooks/post-receive得到了内容:

#!/bin/sh
git --work-tree=/sites/node/cleu --git-dir=/gits/cleu.git
checkout -f

我还有/sites/node/cleu/文件夹

在我的远程计算机上,repo文件夹执行了:

git init
git remote add live ssh://user@vpsipadress/gits/cleu.git
# Some files addition
git add .
git commit -m "Start"
git push live master

我通过ssh登录到vps然后检查我推送的文件,那里有任何东西。什么是正确的步骤?

1 个答案:

答案 0 :(得分:2)

本声明:

  

并且/gits/cleu.git/hooks/post-receive得到了内容:

显示cleu.git是“裸”存储库的指示。 (man git-init中有一些信息,但实际上并不多。)通常,git repo看起来像这样:

.../some-parent-dir
    .git/
        config
        description
        HEAD
        hooks
        ... and so on ...
    < your files >

裸存储库看起来像这样:

.../some-parent-dir.git
    config
    description
    HEAD
    hooks
    ... and so on ...

一个简单的仓库只是一个没有工作目录的仓库。它对于存储存储库及其历史记录很有用,但它并不适合使用它。你经常在遥控器上看到没有点工作目录,因为没有人在那里工作。

有人暗示这是一个简单的回购,而不是正常回购:

  • 没有.git目录。
  • .git目录中的所有内容都在主文件夹中。

此外,路径以.git结尾,例如cleu.git,而不是cleu。这只是一个常见的命名约定,所以不要依赖它,但通常会看到这样的裸存储库。

但是数据在哪里?

历史记录在objects。它以复杂的方式存储;不要试图直接¹。相反,只需尝试克隆回购:

git clone ssh://user@vpsipadress/gits/cleu.git
cd cleu
# Now take a look around.

¹除非您想了解git内部的工作原理。这真的很酷,但有点复杂。 Git Internals应该提供一个起点。

关于那个剧本......

钩子脚本post-receive只是一个可执行文件,这里只是一个shell脚本:

#!/bin/sh
git --work-tree=/sites/node/cleu --git-dir=/gits/cleu.git
checkout -f

但请注意,shell脚本需要命令在一行上,例如:

#!/bin/sh
git --work-tree=/sites/node/cleu --git-dir=/gits/cleu.git checkout -f

(因为这里的命令是git checkout),或者你可以用续行来解决这个问题:

#!/bin/sh
git --work-tree=/sites/node/cleu --git-dir=/gits/cleu.git \
    checkout -f

我缩进它以更清楚地表示继续;这是风格的,并不是严格要求的,但我发现它更具可读性。你甚至可以:

#!/bin/sh
git \
    --work-tree=/sites/node/cleu \
    --git-dir=/gits/cleu.git \
    checkout -f