Do a “git export” (like “svn export”)?

后端 未结 30 2906
暖寄归人
暖寄归人 2020-11-21 22:33

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

相关标签:
30条回答
  • 2020-11-21 23:01

    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

    0 讨论(0)
  • 2020-11-21 23:01

    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.
    0 讨论(0)
  • 2020-11-21 23:01

    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?

    0 讨论(0)
  • 2020-11-21 23:02

    If you want something that works with submodules this might be worth a go.

    Note:

    • MASTER_DIR = a checkout with your submodules checked out also
    • DEST_DIR = where this export will end up
    • If you have rsync, I think you'd be able to do the same thing with even less ball ache.

    Assumptions:

    • You need to run this from the parent directory of MASTER_DIR ( i.e from MASTER_DIR cd .. )
    • DEST_DIR is assumed to have been created. This is pretty easy to modify to include the creation of a DEST_DIR if you wanted to

    cd MASTER_DIR && tar -zcvf ../DEST_DIR/export.tar.gz --exclude='.git*' . && cd ../DEST_DIR/ && tar xvfz export.tar.gz && rm export.tar.gz

    0 讨论(0)
  • 2020-11-21 23:04

    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
    }
    
    0 讨论(0)
  • 2020-11-21 23:05

    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
    
    0 讨论(0)
提交回复
热议问题