在我的 GoDaddy 托管计划上设置 git repo

在我的 GoDaddy 托管计划上设置 git repo

我有一个使用 git 进行版本控制的项目。

我想要做的是在我的(启用 ssh 的)GoDaddy 共享主机包上设置一个 repo,这样我就可以通过推送而不是在 FTP 中进行拖放来进行部署。

任何建议都值得感激。最好是来自已经做过这件事的人的帐户,但我个人在网上找不到任何帐户。

答案1

我在 HostNine 共享主机包上托管的网站上遇到了同样的问题。他们也为您提供ssh访问权限,但不幸的是他们没有git安装,甚至不允许您运行gcc,这使得您的用户下载和安装 git 变得相当困难。

我能想到的唯一解决这些限制的方法是从另一台有 git 二进制文件的计算机复制过来。也许同样的解决方案也适用于您和您的 GoDaddy 共享主机。以下是我所做的:


首先确定您的服务器采用哪种架构。我的情况是 32 位 (i386)。以下是确定架构的几种方法:

# uname -a
Linux ___.myserverhosts.com 2.6.18-128.1.6.el5PAE #1 SMP Wed Apr 1 10:02:22 EDT 2009 i686 i686 i386 GNU/Linux

# file /bin/echo
/bin/echo: ELF 32-bit LSB executable, Intel 80386, version 1 (SYSV), for GNU/Linux 2.6.9, dynamically linked (uses shared libs), for GNU/Linux 2.6.9, stripped

接下来,你需要找到另一台运行相同架构的 Linux 且安装了 git 的计算机。它们甚至不必运行相同的 Linux 发行版或版本,只要它们是相同的架构,并且你可以找到所需的二进制文件和库文件即可。

要查找主 git 二进制文件的位置:

> which git
/usr/local/bin/git

一些其他重要的二进制文件(如git-receive-pack)也位于同一目录中,因此我建议复制所有内容/usr/local/bin/git*以确保获得所需的一切。


git 所依赖的其他重要文件位于源系统某个“libexec”目录下。如果你不复制这些文件,当你尝试执行 时可能会收到一条令人惊讶的错误消息git push,就像我做的那样:

git: 'index-pack' is not a git-command. See 'git --help'.

要查找 target_host 上包含核心 git 库的目录,可以使用以下命令:

> git --exec-path
/usr/local/libexec/git-core

我建议先复制这些文件,然后尝试运行 git,看看它是否会抱怨缺少任何共享库。如果没有,那么你(大概)可以继续了。如果有,那么继续阅读。(如果共享库已经存在于目标主机上并且是正确的版本,则无需复制它们。)

scp您可以使用、rsyncftp或任何您喜欢的方法来复制文件。我使用了scp,如下所示:

> ssh target_host 'mkdir -p ~/bin ~/libexec'
> scp /usr/local/bin/git* target_host:~/bin
> scp -r /usr/local/libexec/git-core target_host:~/libexec

然后 ssh 到 target_host。你需要在你的文件中添加类似下面的几行~/.bashrc

export PATH=$PATH:~/bin
export LD_LIBRARY_PATH=~/lib
export GIT_EXEC_PATH=~/libexec/git-core

如果你忘记了这个步骤,当你执行以下操作时你可能会惊讶地看到这个错误git push

git-receive-pack: command not found

git.or.cz 上的 Git FAQ 对此进行了记录:

基本上,问题在于“git-receive-pack”不在远程端的默认 $PATH 中。

...

  • .bashrc确保在(不仅.bash_profile)中设置了正确的路径

GIT_EXEC_PATH记录于man git

   --exec-path
       Path to wherever your core git programs are installed. 
       This can also be controlled by setting the GIT_EXEC_PATH
       environment variable. If no path is given, git will print
       the current setting and then exit.

获取新资源~/.bashrc。现在尝试运行git


这是它第一次给我的:

> git
git: error while loading shared libraries: libcrypto.so.4: cannot open shared object file: No such file or directory

通过在源机器上运行以下命令,我可以找出要复制的共享库的位置:

> ldd /usr/local/bin/git
libz.so.1 => /usr/lib/libz.so.1 (0xb7fcf000)
libcrypto.so.4 => /lib/libcrypto.so.4 (0xb7ee4000)
libpthread.so.0 => /lib/tls/libpthread.so.0 (0xb7ed2000)
libc.so.6 => /lib/tls/libc.so.6 (0xb7da6000)
libgssapi_krb5.so.2 => /usr/lib/libgssapi_krb5.so.2 (0xb7d92000)
libkrb5.so.3 => /usr/lib/libkrb5.so.3 (0xb7d2d000)
libcom_err.so.2 => /lib/libcom_err.so.2 (0xb7d2a000)
libk5crypto.so.3 => /usr/lib/libk5crypto.so.3 (0xb7d08000)
libresolv.so.2 => /lib/libresolv.so.2 (0xb7cf5000)
libdl.so.2 => /lib/libdl.so.2 (0xb7cf1000)
/lib/ld-linux.so.2 (0xb7fe8000)

就我而言,我只需要复制/lib/libcrypto.so.4~/lib我的上面target_host,一切都很好。


现在您应该可以在共享托管服务器上工作git,并且应该能够推送到它!

现在您需要在服务器上创建一个新的 git 存储库和工作树,或者复制现有的存储库/工作树。


顺便说一句,在这种情况下,我不认为你想要一个裸存储库在服务器上,因为你说你想要部署每当 config HEAD objects/ refs/您执行git push.

toolmantim.com解释常规 git 存储库与裸存储库之间的区别:

默认的 git 存储库假定您将使用它作为工作目录,因此 git 将实际的裸存储库文件与所有项目文件一起存储在 .git 目录中。与工作副本不同,远程存储库不需要文件系统上的文件副本,它们所需要的只是存储库本身的增量和二进制内容。这就是 git 的“裸”含义。只是存储库本身。


我暂时假设您已经在 上创建了一个目录,target_host用于部署您的网站(或任何您要部署的内容)。我们把这个目录称为~/www/my_site。您甚至可能已经通过 ftp 将所有文件传输到~/www/my_site already。(是否已经这样做并不重要。)我还暂时假设您尚未将 .git 子目录复制到~/www/my_site(但如果您已经这样做了,它应该可以正常工作)。

由于 target_host 上尚未初始化 git 存储库,因此您的第一步是创建一个:

> cd ~/www/my_site
> git init

然后,无论哪个主机拥有包含您想要部署的最新更改的存储库(我猜是您的开发箱),您只需执行以下操作即可进行部署:

> git push --all ssh://username@target_host:port/~/www/my_site/.git

target_host如果您的存储库尚未更新,您可能会看到这样的警告:

> warning: updating the current branch
> warning: Updating the currently checked out branch may cause confusion,
> warning: as the index and work tree do not reflect changes that are in HEAD.
> warning: As a result, you may see the changes you just pushed into it
> warning: reverted when you run 'git diff' over there, and you may want
> warning: to run 'git reset --hard' before starting to work to recover.
> warning: 
> warning: You can set 'receive.denyCurrentBranch' configuration variable to
> warning: 'refuse' in the remote repository to forbid pushing into its
> warning: current branch.
> warning: To allow pushing into the current branch, you can set it to 'ignore';
> warning: but this is not recommended unless you arranged to update its work
> warning: tree to match what you pushed in some other way.
> warning: 
> warning: To squelch this message, you can set it to 'warn'.
> warning: 
> warning: Note that the default will change in a future version of git
> warning: to refuse updating the current branch unless you have the
> warning: configuration variable set to either 'ignore' or 'warn'.

(我认为,在正常git使用中,你永远不会看到这条消息,因为你通常会推送到存储库。但由于我们的远程存储库在这种情况下是具有工作树和索引的普通存储库,因此git可以理解的是,我们担心它可能会弄乱一些东西。)

不过,我认为我们可以安全地将其设置为“忽略”在您的服务器上,因为您不太可能直接向那里的存储库进行任何提交。(所有提交可能都应该源自您的开发存储库,然后推送到服务器。)

因此请继续进行设置,这样您就不会在每次按下时都看到警告:

> ssh target_host 'cd ~/www/my_site/; git config receive.denyCurrentBranch ignore'

然而,它push本身只会更新索引,不是工作树本身中的文件。不过,更新这些文件只是我们尝试做的全部工作,因此,直到我们告诉git将索引的内容写入工作树本身时,我们的工作才算完成,如下所示:

> ssh target_host 'cd ~/www/my_site/; git reset --hard'

(注意:您在服务器上的工作树中所做的任何更改都将被存储库中的内容覆盖。)

我还遵循了 mattikus 的建议并为我的服务器创建了一个远程:

> git remote add h9 ssh://username@target_host:port/~/www/my_site/.git

所以现在我要做的就是部署:

> git push --all --force h9
> ssh remote_host 'cd ~/www/my_site/; git reset --hard'

我甚至将这些命令放入我命名的脚本中script/deploy,以便任何时候我想要部署时只需运行一个命令即可。

如果您发现这些说明中有任何错误或者您知道更好的解决方案,请告诉我。

答案2

我既是 SF 也是 godaddy 新手,所以请耐心等待,但无论如何,我很高兴看到这里讨论这个问题。

仅花我的 0.02 美元,我尝试在我的 Linux 机器上(动态)构建 git,将其托管到我的 godaddy 帐户,即使尝试仅推送到其他被动的 godaddy 机器,也会因缺少 openssl 而失败。也许如果我尝试使用 openssl 静态构建 git,但这也感觉是个坏主意。

$ git remote add godaddy ssh://[email protected]//home/content/u/n/c/unclecj/foo.git

$ git push godaddy master
bash: git-receive-pack: command not found
fatal: The remote end hung up unexpectedly

$ git push --receive-pack="/home/content/u/n/c/unclecj/opt/git-1.6.3/bin/git-receive-pack" godaddy master
/home/content/u/n/c/unclecj/opt/git-1.6.3/bin/git-receive-pack: error while loading shared libraries: libcrypto.so.0.9.8: cannot open shared object file: No such file or directory
fatal: The remote end hung up unexpectedly

离题了,但这是我应该从 godaddy 期望到的那种缺乏支持的情况吗,我是否应该后悔没有选择 dreamhosts 呢?

谨致问候 CJ

PS. 这不是答案,而是一个建议,一旦 git-receive 在 godaddy 上运行(是吗?),那么具有分离工作树的存储库就是为 Web 部署的好方法:http://toroid.org/ams/git-website-howto

答案3

最简单的方法是在远程服务器上运行以下命令:

mkdir repo.git
cd repo.git
git init --bare 

然后在你的开发结帐时:

git push --all ssh://<username>@<your server>/~/path/to/repo/relative/to/homedir/repo.git

不需要服务器或任何其他东西,只要您有 ssh 访问权限,就应该能够从该机器获取/拉取。

如果您也设置了 .ssh/config,它应该利用这一点并使用您可能设置的任何私钥。

如果您计划大量推出更新,您可以将远程存储库添加到您的开发签出中:

git remote add godaddy ssh://<username>@<your server>/path/to/repo.git

从那时起你就可以:

git push godaddy

欲了解更多信息,请查看在线文档git push或运行git push --help以在本地启动手册页。

相关内容