0

Can we extract a specific file to a local machine based on the commit id from GIT remote repository without cloning the entire repository.

Found a few answers to this question, but not clear with how to continue with this and if it would actually work the way I am expecting

Using Fetch

git fetch origin 96de5297df870:refs/remotes/origin/foo-commit

With repository cloned to a local machine below is working, but i am looking for a solution without cloning

git show 0311b27:./RN/SIE_R15.3_10646.xls > /d/ReleaseFolder/GitTest/SIE_R15.3_10646.xls

I am using git version 1.9.5.msysgit.1

I have tried this option as well

archive --remote=git://git.foo.com/project.git HEAD:path/to/directory filename | tar -x

but since i am using http protocol, I am getting this error

fatal: Operation not supported by protocol.
Unexpected end of command stream
k0pernikus
  • 60,309
  • 67
  • 216
  • 347
  • If the repo has web-interface, then your question becomes trivial. But if it hasn't, I'm affraid, you have not many options. Have you considered a partial clone with `--depth`? – user3159253 Dec 17 '15 at 12:14
  • @Igal -- Edited my question as well, I have tried this option as well archive --remote=git://git.foo.com/project.git HEAD:path/to/directory filename | tar -x but since i am using http protocol, I am getting this error fatal: Operation not supported by protocol. Unexpected end of command stream – Blesson Mathew Dec 17 '15 at 12:19
  • @user3159253 -- We have gitweb web interface in place but I am looking for a solution using gitbash as the intention is to use it as part of a script – Blesson Mathew Dec 17 '15 at 12:21
  • @user3159253 -- Regarding GIT shallow clone, this is what i have got to know, by providing an argument of --depth 1 to the clone command, the process will copy only the latest revision of everything in the repository. For example: git clone --depth 1 https://github.com/jquery/jquery.git jquery My requirement is to get a file based on the commit id – Blesson Mathew Dec 17 '15 at 12:40
  • Just to confirm did you do the pre-requisite for using `git archive` ? i.e. (from link in the first comment) `you MUST first run this inside the directory of your repository on your git server (where git daemon runs): git config daemon.uploadarch true ` – Ashutosh Jindal Dec 17 '15 at 13:01
  • @BlessonMathew: [virtually] every web interface to a git repo has [RESTful] api to get a particular object from the repo. E,g, gitweb allows you to do something like this: https: //server.com/gitweb?p=repository.git;a=blob_plain;f=FileName.txt;hb=SHA1. So you may use a simple command line tool like `wget` to fetch the object and store it in the FS. – user3159253 Dec 17 '15 at 13:19
  • instead of cloning the whole repo, you may `init` an empty git repo, then `fetch` a given commit to a new reference. `fetch` also supports `--depth`. – user3159253 Dec 17 '15 at 13:22
  • @BlessonMathew What is wrong with the `git archive` solution. There is no requirement that it needs to take any particular protocol. Also, although this is not relevant to your question, you should not be using version 1.9.5.msysgit.1. The most updated version is 2.6+, and it has a much better interface, besides having the most up-to-date version of Git for Windows. – Joseph K. Strauss Dec 17 '15 at 14:48
  • Thanks everyone. Comment from user3159253, where its mentioned to use API from gitweb has helped me resolve my issue, using it with powershell I am able to download files on windows, specific to commit id from repository without a need to clone the whole repository. – Blesson Mathew Dec 17 '15 at 15:39

0 Answers0