Git archive of repository with uncommitted changes

前端 未结 9 711
旧时难觅i
旧时难觅i 2021-02-01 18:31

How can I create an archive of the current repository including local uncommitted changes using git archive?

相关标签:
9条回答
  • 2021-02-01 18:46

    I know this is old, but I think I found a solution.

    Run:

    stashName=`git stash create`;
    git archive <options> $stashName
    

    Since git wants a solid commit to make an archive, we can make a 'one off' commit using git stash. The create command just creates the stash commit (doesn't reset your working directory or push it to the stash stack) and returns the hash for it.

    If you are worried about the space from the dangling commit, you can clean it up with a git gc --prune=now. Otherwise, just wait 2 weeks and it'll disappear.

    0 讨论(0)
  • 2021-02-01 18:52

    Improving nevsan's answer for my purpose - to archive latest code in any case (committed or not):

    uploadStash=`git stash create`; git archive -o code_outgoing.zip ${uploadStash:-HEAD}
    
    0 讨论(0)
  • 2021-02-01 18:52

    If you haven't committed the changes, then git archive won't help you. If you just want a snapshot of your working area, tar is probably your best bet.

    0 讨论(0)
  • 2021-02-01 19:06

    This creates a zip archive containing all working tree files except those that are ignored by git:

    git ls-files --others --exclude-standard --cached  | zip --names-stdin archive.zip
    
    0 讨论(0)
  • 2021-02-01 19:07

    Another solution with git ls-files :

    git ls-files -z | xargs -0 tar -czvf archive.tar.gz
    
    0 讨论(0)
  • 2021-02-01 19:09

    a small bash script based on @fhucho's answer:

    #backup.sh
    #remove final "/"
    repo=${1%"/"} 
    #create $repo-backup.zip
    cd $repo
    git ls-files --others --exclude-standard --cached  | zip --names-stdin ../$repo-backup.zip
    cd ..
    ls -l $repo-backup.zip
    

    usage:

    . backup.sh myrepo
    
    0 讨论(0)
提交回复
热议问题