gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-02 14:22:51 26 4
gpt4 key购买 nike

我正在使用 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 并检查我推送的文件,那里有任何东西。正确的步骤是什么?

最佳答案

这个说法:

And /gits/cleu.git/hooks/post-receive got as content:



出现指示 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 ...

裸仓库只是没有工作目录的仓库。它对于存储存储库及其历史记录很有用,但并不适合使用它。您经常在没有工作目录的 Remote 上看到它,因为没有人在那里工作。

一些暗示它是一个裸仓库,而不是一个普通的仓库:
  • 没有.git目录。
  • .git 中的所有内容目录是在主文件夹中。

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

    但数据在哪里?

    历史在 objects .它以复杂的方式存储;不要试图直接得到它¹。相反,只需尝试克隆 repo:
    git clone ssh://user@vpsipadress/gits/cleu.git
    cd cleu
    # Now take a look around.

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

    关于那个脚本……

    钩子(Hook)脚本 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

    关于VPS 上的 Git 远程存储库接受推送但不创建文件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22925723/

    26 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com