41 Exporting Your Repository

Sharing your repository with other developers is a matter of giving them access to read your public repository, but sometimes you need to give access to content you’re tracking to people who don’t use Git: clients, customers, or business partners of a less tech-savvy variety. You can export the contents of your repository at a particular point to share with these people using the git archive command.

It’s important to remember you are exporting only one point in the history of your repository, not the entire history. Some people look at an export as a backup of their repository. This is not the correct way to do a backup in Git. Each clone of your repository has the entire history, so push your repository to a remote repository on some other computer. Backup finished.

You can specify the point you want to export as either a commit ID, HEAD or some other special commit name, a branch, or a tag. You can also specify a relative revision if you want to export the parent of a certain commit.

Provide a --prefix parameter with a trailing slash when using git archive. That tells Git to put the contents of the archive in its own directory within the archive so it’s expanded into its own directory when you uncompress it.

git archive exports in either a tar format or a zip format. You can specify which you prefer with --format. You can skip the --format parameter if you provide either --output or -o; Git uses the file extension from the file provided to it to determine which type it should export.

You can also pipe the output through other commands to modify the output if you don’t use the --output parameter. The most common use is piping the output through gzip or bzip2 with | gzip > some-file.tar.gz. That turns the tar file into a gzipped tar file. You can also pipe a zip file to gzip, but that would be redundant and repetitive.[18]

You can also export individual directories of your repository in addition to exporting the entire repository. You do this by specifying the revision you want to export and adding a colon and the name of the directory you want to export.

What To Do...
  • Create a tar.gz file of the latest changes in master.
     
    prompt>​ git archive --format=tar
     
    --prefix=my-project-latest/
     
    HEAD | gzip > my-project-latest.tar.gz
     
    prompt>​
     
    ...​ or ...
     
    prompt>​ git archive --prefix=my-project-latest
     
    --output my-project-latest.tar &&
     
    gzip my-project-latest.tar
     
    prompt>
  • Create a zip of the repository at tag v1.0.2.
     
    prompt>​ git archive --format=zip
     
    --prefix=my-project-1.0.2/
     
    v1.0.2 > my-project-1.0.2.zip
     
    prompt>​
     
    ...​ or ...
     
    prompt>​ git archive --prefix=my-project-1.0.2/
     
    v1.0.2 -o my-project-1.0.2.zip
     
    prompt>
  • Export one directory.
     
    prompt>​ git archive --format=zip
     
    --prefix=my-project/
     
    HEAD:<some directory> > my-project.zip
     
    prompt>

Related Tasks

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.225.95.245