简体   繁体   中英

Git: get a particular revision of a git repository with depth 1

How do I obtain a single revision from a git repository without cloning the whole repository ?

Note : this question has been asked 100s of times but I have yet to see an answer that solves it since they all start with "clone the whole git repository". This cannot be done in my use case.

The best I can do is:

  1. Find the depth of the commit.
  2. Clone until that depth: git clone --depth $depth $git_repo_url .
  3. Checkout and reset: git checkout $commit_hash; git reset --hard git checkout $commit_hash; git reset --hard .

But this still requires cloning up to the commits depth.

Is there a way to avoid that and clone only a particular commit with depth 1?

Not with clone but with pull / fetch . See this post:

  1. How to clone git repository with specific revision/changeset?

  2. Retrieve specific commit from a remote Git repository

     git init git fetch --depth 1 url://to/source/repository <sha1-of-commit> 

And set uploadpack.allowReachableSHA1InWant on the server side.

如果您进行reflog和git cherry-pick怎么样

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM