Git Archive but first put all the files inside a folder then start archiving

As title suggest, I want to know if there is a single git command that put all my project in one folder first (not including .gitignored files) and then proceed archiving the folder— leaving ignored files not included when archiving which is nice.

This can be beneficial for me as I am working on WordPress plugin with multiple release. Some references.

Related posts

Leave a Reply

2 comments

  1. I want all the files (minus the .gitignored files) move to a folder first then proceed archiving that folder

    It is possible in one command provided you define an alias but this isn’t git-related:
    you can:

    • clone your repo elsewhere (that way you don’t get any ignored or private file)
    • move your files as you see fit in that local clone
    • archive (tar cpvf yourArchive.tar yourFolder)

    But git archive alone won’t help you move those files, which is why I would recommend a script with custom bash commands (not git commands).

  2. You don’t really need to copy / clone the repo anywhere.

    1. Make sure you committed all your changes.
    2. Process the files any way you want.
    3. Run tar -cvjf dist/archive-name.tbz2 --transform='s,^,archive-name/,' $(git ls-tree --full-tree -r --name-only --full-name HEAD)
    4. run git reset --hard to restore without any of the changes you made in step #2.

    Hints:

    • The --transform='s,^,archive-name/,' is so your files will be extracted toarchive-name/….`, you can remove it if you don’t need that.