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

后端 未结 30 2903
暖寄归人
暖寄归人 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:50

    If you need submodules as well, this should do the trick: https://github.com/meitar/git-archive-all.sh/wiki

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

    I found out what option 2 means. From a repository, you can do:

    git checkout-index -a -f --prefix=/destination/path/
    

    The slash at the end of the path is important, otherwise it will result in the files being in /destination with a prefix of 'path'.

    Since in a normal situation the index contains the contents of the repository, there is nothing special to do to "read the desired tree into the index". It's already there.

    The -a flag is required to check out all files in the index (I'm not sure what it means to omit this flag in this situation, since it doesn't do what I want). The -f flag forces overwriting any existing files in the output, which this command doesn't normally do.

    This appears to be the sort of "git export" I was looking for.

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

    From the Git Manual:

    Using git-checkout-index to "export an entire tree"

    The prefix ability basically makes it trivial to use git-checkout-index as an "export as tree" function. Just read the desired tree into the index, and do:

    $ git checkout-index --prefix=git-export-dir/ -a

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

    I use git-submodules extensively. This one works for me:

    rsync -a ./FROM/ ./TO --exclude='.*'
    
    0 讨论(0)
  • 2020-11-21 22:54

    I have another solution that works fine if you have a local copy of the repository on the machine where you would like to create the export. In this case move to this repository directory, and enter this command:

    GIT_WORK_TREE=outputdirectory git checkout -f

    This is particularly useful if you manage a website with a git repository and would like to checkout a clean version in /var/www/. In this case, add thiscommand in a .git/hooks/post-receive script (hooks/post-receive on a bare repository, which is more suitable in this situation)

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

    Probably the simplest way to achieve this is with git archive. If you really need just the expanded tree you can do something like this.

    git archive master | tar -x -C /somewhere/else
    

    Most of the time that I need to 'export' something from git, I want a compressed archive in any case so I do something like this.

    git archive master | bzip2 >source-tree.tar.bz2
    

    ZIP archive:

    git archive --format zip --output /full/path/to/zipfile.zip master 
    

    git help archive for more details, it's quite flexible.


    Be aware that even though the archive will not contain the .git directory, it will, however, contain other hidden git-specific files like .gitignore, .gitattributes, etc. If you don't want them in the archive, make sure you use the export-ignore attribute in a .gitattributes file and commit this before doing your archive. Read more...


    Note: If you are interested in exporting the index, the command is

    git checkout-index -a -f --prefix=/destination/path/
    

    (See Greg's answer for more details)

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