I\'ve been wondering whether there is a good \"git export\" solution that creates a copy of a tree without the .git
repository directory. There are at least thr
This will copy the files in a range of commits (C to G) to a tar file. Note: this will only get the files commited. Not the entire repository. Slightly modified from Here
Example Commit History
A --> B --> C --> D --> E --> F --> G --> H --> I
git diff-tree -r --no-commit-id --name-only --diff-filter=ACMRT C~..G | xargs tar -rf myTarFile.tar
git-diff-tree Manual Page
-r --> recurse into sub-trees
--no-commit-id --> git diff-tree outputs a line with the commit ID when applicable. This flag suppressed the commit ID output.
--name-only --> Show only names of changed files.
--diff-filter=ACMRT --> Select only these files. See here for full list of files
C..G --> Files in this range of commits
C~ --> Include files from Commit C. Not just files since Commit C.
| xargs tar -rf myTarFile --> outputs to tar
As I understand the question, it it more about downloading just certain state from the server, without history, and without data of other branches, rather than extracting a state from a local repository (as many anwsers here do).
That can be done like this:
git clone -b someBranch --depth 1 --single-branch git://somewhere.com/repo.git \
&& rm -rf repo/.git/
--single-branch
is available since Git 1.7.10 (April 2012).--depth
is (was?) reportedly faulty, but for the case of an export, the mentioned issues should not matter.By far the easiest way i've seen to do it (and works on windows as well) is git bundle
:
git bundle create /some/bundle/path.bundle --all
See this answer for more details: How can I copy my git repository from my windows machine to a linux machine via usb drive?
If you want something that works with submodules this might be worth a go.
Note:
Assumptions:
cd MASTER_DIR && tar -zcvf ../DEST_DIR/export.tar.gz --exclude='.git*' . && cd ../DEST_DIR/ && tar xvfz export.tar.gz && rm export.tar.gz
i have the following utility function in my .bashrc file: it creates an archive of the current branch in a git repository.
function garchive()
{
if [[ "x$1" == "x-h" || "x$1" == "x" ]]; then
cat <<EOF
Usage: garchive <archive-name>
create zip archive of the current branch into <archive-name>
EOF
else
local oname=$1
set -x
local bname=$(git branch | grep -F "*" | sed -e 's#^*##')
git archive --format zip --output ${oname} ${bname}
set +x
fi
}
a git export to a zip archive while adding a prefix (e.g. directory name):
git archive master --prefix=directoryWithinZip/ --format=zip -o out.zip