简体   繁体   中英

Download latest version of a specific GIT branch + no local repository

I have a Bamboo CI system with multiple agents (ie distributed), each build gets assigned to the next available agent; Also note that multiple builds of different branches of the same repository might run concurrently on the same machine

My build needs to checkout the code from a remote git repository and that is as far as the integration with git goes.

Currently the build clones the repository prior to each build (hard requirement) and keeps the complete git repository (ie .git directory) for each of the branches on the same file system.

As the build does not interact with git in any way (eg push, pull) other than checking out the latest code I would like to simply, in lamens terms, download the latest version of a given git branch and nothing more.

Would appreciate any assistance

I'm by no means a git expert, but maybe this similar Stack Overflow question will help point you in the right direction:

Do a "git export" (like "svn export")?

OK, this is how I would do it:

Setup:

git init build_dir
cd build_dir
# repeat for all repositories
git remote add REPO_NAME GIT_REPO_URI

Checkout a specific branch:

git fetch --all # fetch all updates
git fetch REPO_NAME # just fetch one repo
git checkout master
git reset --hard REPO_NAME/repository

Once in a while run:

git gc --aggressive

事实证明,在选中“ Shallow clone”(浅克隆)选项时,Bamboo 3.4大致遵循了Let_Me_Be的建议(该选项具有更酷的功能,例如多存储库计划,签出任务和git子模块)

git clone -b branchname --depth 1 git@git.example.com:repository.git /path/to/your/repo

This will create a so called "shallow clone". It only contains the very latest commit of the named branch. Thus you will only pull the absolutely necessary bits.

To cite from the git clone man page :

--depth <depth>
    Create a shallow clone with a history truncated to the specified number
    of revisions. A shallow repository has a number of limitations (you cannot clone
    or fetch from it, nor push from nor into it), but is adequate if you are only
    interested in the recent history of a large project with a long history, and would
    want to send in fixes as patches.

Edit: AFAIK git can not "export" from a remote directory directly. But the approach above is roughly equivalent to an export from remote. If you then don't want the .git directory, just remove it. This is way easier than in the SVN world as you have exactly one, not one in every freaking directory.

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