Pregunta

When we build our application, we fetch code from a directory of a CVS repository first then build it. So in Git, do we have anything similar to do it. I just want to checkout from a specfic diectory of Git repo and then build our code. No local repo maintainance, nothing. Just code checkout.

I know there is something called "Sparse checkout". Do we have anything simpler?

My problem is that this build script can be run on any server. So if I choose Sparse checkout, I will have to go on each server ,set-up Git and and tell it how to do sparse checkout.

¿Fue útil?

Solución

To answer litteraly to your question, you'd have to do the following:

Retrieve repo data in a temporary directory

mkdir path/to/temporary && cd path/to/temporary
git clone <repo-url> --depth 1 --bare

And checkout the directory you want in another one

git --work-tree=/path/to/checkout checkout HEAD -- sub/directory

You can then delete the temporary and work with the checkout.

This can be easily put in a script of course!

Otros consejos

Git philosophy is miles away from CVS, so I suggest you to act differently here. Your Git repositories will be distributed, every developper or server will have a copy of it, with one being authoritative among these (origin remote in Git terms).

When you want to start a build from a fresh checkout, you first say Git to grab the latest changes from origin, this is called a fetch.

git fetch origin

Then, to have a fresh checkout, you want your filesystem to be exactly the same as the server version, without any other file.

git checkout --force origin/master
git clean -d --force

The advantage here is that the network operation is very efficient, you grab only the latest diffs from the server you want to sync with, and you're still sure that you're building from the right files, without them being changed.

You'll want to check also tools for Continuous Integration, like Jenkins, which quite well integrated with Git repositories.

You can try cloning your repository using the --depth option, to see if it fits your need. --depth option won't clone the full repository history, and thus, will be faster.

> git clone http://myrepo.git --depth 1

You can further restrict the checkout by specifying a branch name :

> git clone http://myrepo.git -b master --depth 1

If you want to checkout only a subdirectory of a git repository, AFAIK, it is not currently possible.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top