【问题标题】:Git serve: I would like it that simpleGit 服务:我希望它这么简单
【发布时间】:2008-12-18 08:34:56
【问题描述】:

我想知道如何简单地通过 http = 发布,就像Mercurial 的 hg serve 一样!在 Windows/work 框中执行以下操作:

git serve 

然后在 Linux 机器上简单地运行:

git clone http://project project 

完成了。

【问题讨论】:

  • 您是否知道克隆 svn 存储库的 git-svn 克隆很棘手? subtlegradient.com/articles/2008/04/22/cloning-a-git-svn-clone
  • 为什么不直接在你的 linux notebook 上安装 svn 并直接从项目存储库中检出? Git 可能是新的热点,但在这种特殊情况下,你似乎真的让你的生活变得不必要地复杂。
  • bendin 不,我不知道这很棘手,因为我现在正在设置环境,我很高兴你发言...
  • 首先:我的笔记本不允许进入这个vpn,所以我不能直接访问svn。其次:我想提交到我自己的存储库,使用 git 的全部意义在于我可以进行本地提交、分支和轻松合并。我发现现在使用 svn 很费劲。
  • 如果你安装了 python,一个简单的 git instaweb -d python 可能就不够了(使用 Git 2.21,2019 年 2 月):请参阅 my answer below

标签: windows git mercurial


【解决方案1】:

导航到您的项目并使用以下开关启动 git-daemon:

cd project
git daemon --reuseaddr --base-path=. --export-all --verbose

这告诉 git-daemon 提供当前目录中的所有项目(我假设是包含 .git/ 文件夹的项目目录)。如果您将其关闭并重新启动过快,它还会告诉它重新使用相同的地址。

您可以将其放入一个批处理脚本中,该脚本具有易于记忆的名称,例如“gitserve”,因此您无需再次全部输入。正如一些 cmets 所建议的,在最新版本的 Git 中,您可以add an alias to the Git config

[alias]
    serve = !git daemon --reuseaddr --verbose --base-path=. --export-all ./.git

在服务器(您的 Windows 机器)上完成后,您可以:

git serve

git-daemon 使用 git:// 协议进行传输,因此在客户端(您的 Linux 机器)上,您需要这样做:

git clone git://123.456.789.111/ project

【讨论】:

【解决方案2】:

与其编写自己的批处理脚本,不如使用gitjour。它知道如何正确启动 git daemon 并将通过 mDNS 广播克隆 URL,因此您可以在 linux 框上执行 gitjour show 并复制和粘贴。

也是一篇很好的文章,概述了 gitjour 和 Nic 博士的许多其他类似工具,What is *jour and why they are killer apps for RailsCamp08

【讨论】:

    【解决方案3】:

    当前使用两个别名 - serve 和 hub。服务于只读共享和集线器用于读/写共享:

    [alias]
      serve = !git daemon --base-path=. --export-all --reuseaddr --informative-errors --verbose
      hub = !git daemon --base-path=. --export-all --enable=receive-pack --reuseaddr --informative-errors --verbose
    

    另外,还有更详细的关于通过 git daemon 分享的教程:http://l.rw.rw/git-daemon

    【讨论】:

      【解决方案4】:

      如果您只是想使用 Web 浏览器公开存储库

      git-instaweb

      $ git instaweb -d apache2 --start
      $ lynx localhost:1234
      

      【讨论】:

      • 上面写着lighttpd not found. Install lighttpd or use --httpd to specify another httpd daemon.
      • @syedrakib 您需要安装 lighttpd、apache2 或其他。我个人在 OS X 上使用git instaweb -d webrick,因为 webrick 自带 Ruby,它预装在 OS X 上。
      • 这个工具似乎与 Windows 不兼容。由于发帖人要求使用 Windows 工具,因此这是此答案的一个重要因素。
      【解决方案5】:

      这是另一种方法。你需要安装 python。

      • 运行git update-server-info
      • 进入.git目录
      • 运行python -mSimpleHTTPServer

      (只需在你的 gitconfig 中创建一个别名)

      现在您可以使用 git pull http://HOST_NAME:8000/ 拉取 repo

      PS:当使用 git daemon 解决方案时,你可以设置--base-path=.git 所以 url 是git://HOST/

      【讨论】:

        【解决方案6】:

        git-webui 是一个 git 扩展,它提供了一个基于 Web 的用户界面以及从其他计算机克隆/拉取的能力

        https://github.com/alberthier/git-webui

        $ cd my_git_repo
        $ git webui
        

        其他人可以

        $ git clone http://<ip-of-your-computer>:8000/ repoclone
        

        $ git pull http://<ip-of-your-computer>:8000/
        

        【讨论】:

        • 我只是盲目地尝试了它。我能够 git clone 但无法访问 webgui。看起来浏览器正在等待服务器的响应。
        【解决方案7】:

        在 .git/config 中添加以下行

        [instaweb]
                       local = true
                       httpd = webrick
                       port = 4231
        

        然后执行

        git instaweb
        

        【讨论】:

          【解决方案8】:

          Git 2.21(2019 年 2 月)允许您将 python 和 git instaweb 结合起来:

          参见Arti Zirk (artizirk)commit 2eb14bb(2019 年 1 月 28 日)。
          (由 Junio C Hamano -- gitster -- 合并于 commit abf39e3,2019 年 2 月 5 日)

          git-instaweb:添加 Python 内置 http.server 支持

          有了这个补丁,可以通过-d python 选项使用Python http.server CGI 处理程序启动git-instaweb

          git-instaweb 围绕http.server(在GIT_DIR/gitweb/)生成一个小包装器,解决了CGI 处理程序的限制,其中CGI 脚本必须位于cgi-bin 子目录中,并且目录索引不能轻易更改.为了使实现保持较小,gitweb 在 url /cgi-bin/gitweb.cgi 上运行,并且自动 打开/时完成重定向。

          生成的包装器与 Python 2 和 3 兼容。

          Python 默认安装在大多数现代 Linux 发行版上 这可以在不需要的情况下运行git instaweb -d python 还有什么。

          【讨论】:

            猜你喜欢
            • 1970-01-01
            • 1970-01-01
            • 2016-04-01
            • 1970-01-01
            • 1970-01-01
            • 2010-09-11
            • 2015-09-18
            • 1970-01-01
            • 2012-04-16
            相关资源
            最近更新 更多