How to clone a specific version of a git repository?

前端 未结 3 560
悲哀的现实
悲哀的现实 2021-01-03 03:59

I\'m working with symfony2 and I want to backup my vendors in case github is not reachable.

How do I clone a specific Version of a repository?

I want to back

相关标签:
3条回答
  • 2021-01-03 04:43

    What I would do to tell git to use this exact version is:

    git clone http://github.com/symfony/symfony.git
    cd symfony
    
    git checkout v2.0.9
    

    One liner:

    git clone http://github.com/symfony/symfony.git -b v2.0.9
    
    0 讨论(0)
  • 2021-01-03 04:53

    You can't clone a repository specifying only a version number. You also can't clone a repository by specifying only a commit hash. (which is pretty much the same thing from Git's point of view)

    Actually the only thing you can do is a shallow clone by specifying the depth (the number of commits you will pull): http://linux.die.net/man/1/git-clone

    git clone --depth 1 would pull only the last commit.

    Back to your question, if you fear that github is unreachable, you should host these projects on one of your server.

    0 讨论(0)
  • 2021-01-03 04:55

    The following might get you there:

    git clone --branch <branch> <repo>
    

    If you are looking for a specific version, then first create a branch off that version from your working repository. Like such:

    # In a local, working repository
    git checkout -b v2.0.9-br v2.0.9
    git push origin
    
    # Now create your clone from v2.0.9-br
    

    Note, I've assumed v2.0.9 is a version (tag), not a branch. If it is a branch, then just clone with the '--branch' option.

    0 讨论(0)
提交回复
热议问题