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

后端 未结 30 2873
暖寄归人
暖寄归人 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 22:44

    I needed this for a deploy script and I couldn't use any of the above mentioned approaches. Instead I figured out a different solution:

    #!/bin/sh
    [ $# -eq 2 ] || echo "USAGE $0 REPOSITORY DESTINATION" && exit 1
    REPOSITORY=$1
    DESTINATION=$2
    TMPNAME="/tmp/$(basename $REPOSITORY).$$"
    git clone $REPOSITORY $TMPNAME
    rm -rf $TMPNAME/.git
    mkdir -p $DESTINATION
    cp -r $TMPNAME/* $DESTINATION
    rm -rf $TMPNAME
    
    0 讨论(0)
  • As simple as clone then delete the .git folder:

    git clone url_of_your_repo path_to_export && rm -rf path_to_export/.git

    0 讨论(0)
  • 2020-11-21 22:46

    git archive also works with remote repository.

    git archive --format=tar \
    --remote=ssh://remote_server/remote_repository master | tar -xf -
    

    To export particular path inside the repo add as many paths as you wish as last argument to git, e.g.:

    git archive --format=tar \
    --remote=ssh://remote_server/remote_repository master path1/ path2/ | tar -xv
    
    0 讨论(0)
  • 2020-11-21 22:47

    Yes, this is a clean and neat command to archive your code without any git inclusion in the archive and is good to pass around without worrying about any git commit history.

    git archive --format zip --output /full/path/to/zipfile.zip master 
    
    0 讨论(0)
  • 2020-11-21 22:49

    The equivalent of

    svn export . otherpath
    

    inside an existing repo is

    git archive branchname | (cd otherpath; tar x)
    

    The equivalent of

    svn export url otherpath
    

    is

    git archive --remote=url branchname | (cd otherpath; tar x)
    
    0 讨论(0)
  • 2020-11-21 22:50

    This will copy all contents, minus the .dot files. I use this to export git cloned projects into my web app's git repo without the .git stuff.

    cp -R ./path-to-git-repo /path/to/destination/

    Plain old bash works just great :)

    0 讨论(0)
提交回复
热议问题