Reputation: 2667
In Perforce, you can actually create a clientspec (workspace), and use "-p" option when syncing down Perforce code. This way it doesn't touch the file table in Perforce server, and makes the syncing much faster. It's basically copy and paste files from the Perforce server.
We are experimenting such operation on Git side, but couldn't find an exact replica of this Perforce command.
Is there an equivalence of this?
I know git reset --hard <commit>
will work, but that's if you already used git clone
and obtained a local copy of the files. In our cases, assume we never run git clone
in the local machine.
I'm asking in this situation because I'm doing SCM release build, and the source code from Git need to sync down to the build machine at a specific SHA, but doesn't have git clone
ran in the past.
Thanks.
Upvotes: 1
Views: 2514
Reputation: 133812
You can configure git-daemon to allow the "upload-archive" service (see the git-daemon manpage), and this allows for a client to simply request an archive of a particular snapshot from the git repository, using the git archive --remote
command, rather than having to download the whole database.
e.g. this will download a snapshot of some project called "cmstool" at version 1.0.0 from a remote server:
git archive --format=tar \
--prefix=cmstool-1.0.0/ \
--remote=git://git/cmstool.git v1.0.0 | tar xf -
Upvotes: 4
Reputation: 9942
git is not designed to only get specific versions of files, but the history. Is there really a problem with doing a git clone
first and git fetch
when updates need to happen? Updates use diffs so can be much faster than copying all the files, and a git repository is often not that much larger than the current state.
That said, there are a few approaches to not copy all the history:
git clone --depth 1
will only get the recent history, but it still fetches all branches. It also is not a terribly useful clone, as many common operations will not work. This may not be a problem in your use-case.git init; git remote add -t <branch> origin <url>; git fetch origin/branch; git checkout origin/branch
git archive
can create a snapshot which can be downloaded as a separate file, and then extracted.Upvotes: 0