如何从其zip中克隆git存储库

Les*_*sto 37 git zip github git-clone

我正在尝试克隆github上的远程存储库,但它很大,我的连接似乎不够稳定,所以我无法成功克隆它.

但是我已经成功下载了存储库的.zip.

有没有办法使用这个由git clone创建的zip,所以我可以推,拉等...?

fra*_*mac 25

这里的相关帖子提供了获取.git目录所需的信息并简化了umläute提供的答案:

  • .git通过克隆裸存储库来获取目录

    $ mkdir repo
    $ git clone --bare http://github/user/repo repo
    
    Run Code Online (Sandbox Code Playgroud)
  • 创建.git目录并移动克隆的文件

    $ mkdir repo/.git
    $ mv repo/* repo/.git
    
    Run Code Online (Sandbox Code Playgroud)
  • 解压缩存储库

    $ unzip repo.zip
    
    Run Code Online (Sandbox Code Playgroud)
  • 重新初始化存储库

    $ cd repo
    $ git init
    
    Run Code Online (Sandbox Code Playgroud)
  • 确认您已同步

    $ git pull
    
    Run Code Online (Sandbox Code Playgroud)
  • 重置HEAD以清除状态

    $ git reset HEAD
    
    Run Code Online (Sandbox Code Playgroud)
  • 这是repo的日志... repo location - http://github.com/udacity/fullstack-nanodegree-vm

    $ git log
    commit ebcbda650bc81d7f4856f5314a0689cea5b43086
    Merge: 574774b b5b787e
    Author: Karl Krueger <karl@udacity.com>
    Date:   Tue Apr 7 11:39:54 2015 -0700`
    
            Merge pull request #3 from pmallory/sharedDirAlert
    
            Add a login alert to explain how to access Vagrant's shared directory
    
    commit b5b787efdb1ecec0c3c9c7f9c0fd4732f984fcb3
    Author: Philip Mallory <philip@udacity.com>
    Date:   Mon Apr 6 15:40:32 2015 -0700`
    
           move the alert into the motd
    
    commit b8012f33c86b0d19fc4c2b972af092e88d00978f
    Author: Philip Mallory <philip@udacity.com>
    Date:   Mon Apr 6 14:32:01 2015 -0700`
    
           Add a login alert to explain how to access Vagrant's shared directory
    
    commit 574774ba29ccd661154431d5600240f090440c37
    Author: Lorenzo Brown <lorenzo@udacity.com>
    Date:   Wed Mar 11 14:08:02 2015 -0700`
    
           Update pg_config.sh
    
           Added installs for Auth&Auth
    
    commit 88fc5537b1a0017a1d76af4587a22412473809a4
    Author: Lorenzo Brown <lorenzo@udacity.com>
    Date:   Wed Mar 4 13:00:25 2015 -0800`
    
           Update and rename vagrant to vagrant/catalog/README.txt
    
    commit f978cdc14c62b7295d8da1a95452faaa1bd108b8
    Author: Lorenzo Brown <lorenzo@udacity.com>
    Date:   Wed Feb 4 11:06:03 2015 -0800`
    
           Update Vagrantfile
    
           switched to port forwarding on 8080
    
    commit d6a3a26578ef3c6d01d28abca76d817938892c7f
    Author: Lorenzo Brown <lorenzo@udacity.com>
    Date:   Tue Feb 3 14:52:34 2015 -0800`
    
           Update Vagrantfile
    
           Added:
    
           config.vm.network "forwarded_port", guest: 80, host: 8080
           config.vm.network "forwarded_port", guest: 5000, host: 5000
    
           FSF uses these two ports for lessons 2 & 3 respectively.
    
    commit 752a79e408c7328ef7f1766d1b97bb468ffed90a
    Author: Mike Wales <michael.wales@udacity.com>
    Date:   Mon Feb 2 11:21:29 2015 -0800`
    
           Removed .vagrant directory
    
    commit 5af9d19adf9ab19b1d886f6cc78e556f864b42dd
    Author: Mike Wales <michael.wales@udacity.com>
    Date:   Mon Feb 2 11:16:45 2015 -0800`
    
           Initial commit.
    
    Run Code Online (Sandbox Code Playgroud)


uml*_*ute 12

如果您已下载存储库(包括.git目录),则非常简单.

在实践中,似乎从github下载的"zip" 包含.git目录,所以这没有帮助:-(

你可能最好的选择是在有稳定访问权限的机器上进行克隆,然后压缩.git目录并以某种方式获取....

  • “实际上,从github下载的“ zip”似乎不包含.git目录,所以这无济于事”那么留下这个答案的意义何在? (2认同)

arc*_*lix 9

虽然接受的答案可以解决问题,但这似乎更为直截了当.

unzip <repo>.zip
cd <repo>
git init
git add .
git remote add origin https://github.com/<user>/<repo>.git
git remote update
git checkout master
Run Code Online (Sandbox Code Playgroud)

只需确保用你的github用户名和你的回购名称替换<user>&<repo>;;)

  • @arctelix 我尝试了你的解决方案和公认的解决方案。但是在这两种情况下,当我按照接受的解决方案执行 git remote update 或 git pull 时,它会再次开始接收整个项目并从 0 开始接收对象。然后下载 zip 的整个点就变得无关紧要了。 (2认同)