How to append branch name and commit to git archive output file?











up vote
3
down vote

favorite
2












I'am using git archive to create a zip file with latest version/HEAD but would like to add the branch name and the commit to the zip filename. How can I achieve this?










share|improve this question


























    up vote
    3
    down vote

    favorite
    2












    I'am using git archive to create a zip file with latest version/HEAD but would like to add the branch name and the commit to the zip filename. How can I achieve this?










    share|improve this question
























      up vote
      3
      down vote

      favorite
      2









      up vote
      3
      down vote

      favorite
      2






      2





      I'am using git archive to create a zip file with latest version/HEAD but would like to add the branch name and the commit to the zip filename. How can I achieve this?










      share|improve this question













      I'am using git archive to create a zip file with latest version/HEAD but would like to add the branch name and the commit to the zip filename. How can I achieve this?







      git git-archive






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Feb 20 '13 at 17:19









      Orlando

      30319




      30319
























          2 Answers
          2






          active

          oldest

          votes

















          up vote
          2
          down vote



          accepted










          You can run this script:



          #!/bin/sh
          sha1=`git rev-parse --short --verify HEAD`
          branch=`git symbolic-ref -q --short HEAD`

          git archive -o latest_${branch}_${sha1}.zip HEAD


          Call it git-auto-archive, for example, make it executable, put in your path, and run it with



          git auto-archive





          share|improve this answer





















          • Thanks, that worked correctly.
            – Orlando
            Feb 20 '13 at 17:36


















          up vote
          0
          down vote













          In addition of CharlesB's script, make sure yo use Git 2.20+ (Q4 201), because git archive -o latest_${branch}_${sha1}.zip can produce a tar file instead of a zip one (bug which has been fixed), if use for a --remote repo.



          See commit 00436bf (25 Oct 2018) by Josh Steadmon (``).

          Helped-by: Jeff King (peff).
          (Merged by Junio C Hamano -- gitster -- in commit a5ab66e, 06 Nov 2018)




          archive: initialize archivers earlier



          Initialize archivers as soon as possible when running git archive.

          Various non-obvious behavior depends on having the archivers initialized, such as determining the desired archival format from the provided filename.



          Since 08716b3 ("archive: refactor file extension format-guessing",
          2011-06-21, Git v1.7.7-rc0), archive_format_from_filename() has used the registered
          archivers to match filenames (provided via --output) to archival
          formats.



          However, when git archive is executed with --remote, format detection happens before the archivers have been registered.

          This causes archives from remotes to always be generated as TAR files, regardless of
          the actual filename (unless an explicit --format is provided).



          This patch fixes that behavior; archival format is determined properly
          from the output filename, even when --remote is used.







          share|improve this answer





















            Your Answer






            StackExchange.ifUsing("editor", function () {
            StackExchange.using("externalEditor", function () {
            StackExchange.using("snippets", function () {
            StackExchange.snippets.init();
            });
            });
            }, "code-snippets");

            StackExchange.ready(function() {
            var channelOptions = {
            tags: "".split(" "),
            id: "1"
            };
            initTagRenderer("".split(" "), "".split(" "), channelOptions);

            StackExchange.using("externalEditor", function() {
            // Have to fire editor after snippets, if snippets enabled
            if (StackExchange.settings.snippets.snippetsEnabled) {
            StackExchange.using("snippets", function() {
            createEditor();
            });
            }
            else {
            createEditor();
            }
            });

            function createEditor() {
            StackExchange.prepareEditor({
            heartbeatType: 'answer',
            convertImagesToLinks: true,
            noModals: true,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: 10,
            bindNavPrevention: true,
            postfix: "",
            imageUploader: {
            brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
            contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
            allowUrls: true
            },
            onDemand: true,
            discardSelector: ".discard-answer"
            ,immediatelyShowMarkdownHelp:true
            });


            }
            });














             

            draft saved


            draft discarded


















            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f14985956%2fhow-to-append-branch-name-and-commit-to-git-archive-output-file%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown

























            2 Answers
            2






            active

            oldest

            votes








            2 Answers
            2






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes








            up vote
            2
            down vote



            accepted










            You can run this script:



            #!/bin/sh
            sha1=`git rev-parse --short --verify HEAD`
            branch=`git symbolic-ref -q --short HEAD`

            git archive -o latest_${branch}_${sha1}.zip HEAD


            Call it git-auto-archive, for example, make it executable, put in your path, and run it with



            git auto-archive





            share|improve this answer





















            • Thanks, that worked correctly.
              – Orlando
              Feb 20 '13 at 17:36















            up vote
            2
            down vote



            accepted










            You can run this script:



            #!/bin/sh
            sha1=`git rev-parse --short --verify HEAD`
            branch=`git symbolic-ref -q --short HEAD`

            git archive -o latest_${branch}_${sha1}.zip HEAD


            Call it git-auto-archive, for example, make it executable, put in your path, and run it with



            git auto-archive





            share|improve this answer





















            • Thanks, that worked correctly.
              – Orlando
              Feb 20 '13 at 17:36













            up vote
            2
            down vote



            accepted







            up vote
            2
            down vote



            accepted






            You can run this script:



            #!/bin/sh
            sha1=`git rev-parse --short --verify HEAD`
            branch=`git symbolic-ref -q --short HEAD`

            git archive -o latest_${branch}_${sha1}.zip HEAD


            Call it git-auto-archive, for example, make it executable, put in your path, and run it with



            git auto-archive





            share|improve this answer












            You can run this script:



            #!/bin/sh
            sha1=`git rev-parse --short --verify HEAD`
            branch=`git symbolic-ref -q --short HEAD`

            git archive -o latest_${branch}_${sha1}.zip HEAD


            Call it git-auto-archive, for example, make it executable, put in your path, and run it with



            git auto-archive






            share|improve this answer












            share|improve this answer



            share|improve this answer










            answered Feb 20 '13 at 17:30









            CharlesB

            58k19145168




            58k19145168












            • Thanks, that worked correctly.
              – Orlando
              Feb 20 '13 at 17:36


















            • Thanks, that worked correctly.
              – Orlando
              Feb 20 '13 at 17:36
















            Thanks, that worked correctly.
            – Orlando
            Feb 20 '13 at 17:36




            Thanks, that worked correctly.
            – Orlando
            Feb 20 '13 at 17:36












            up vote
            0
            down vote













            In addition of CharlesB's script, make sure yo use Git 2.20+ (Q4 201), because git archive -o latest_${branch}_${sha1}.zip can produce a tar file instead of a zip one (bug which has been fixed), if use for a --remote repo.



            See commit 00436bf (25 Oct 2018) by Josh Steadmon (``).

            Helped-by: Jeff King (peff).
            (Merged by Junio C Hamano -- gitster -- in commit a5ab66e, 06 Nov 2018)




            archive: initialize archivers earlier



            Initialize archivers as soon as possible when running git archive.

            Various non-obvious behavior depends on having the archivers initialized, such as determining the desired archival format from the provided filename.



            Since 08716b3 ("archive: refactor file extension format-guessing",
            2011-06-21, Git v1.7.7-rc0), archive_format_from_filename() has used the registered
            archivers to match filenames (provided via --output) to archival
            formats.



            However, when git archive is executed with --remote, format detection happens before the archivers have been registered.

            This causes archives from remotes to always be generated as TAR files, regardless of
            the actual filename (unless an explicit --format is provided).



            This patch fixes that behavior; archival format is determined properly
            from the output filename, even when --remote is used.







            share|improve this answer

























              up vote
              0
              down vote













              In addition of CharlesB's script, make sure yo use Git 2.20+ (Q4 201), because git archive -o latest_${branch}_${sha1}.zip can produce a tar file instead of a zip one (bug which has been fixed), if use for a --remote repo.



              See commit 00436bf (25 Oct 2018) by Josh Steadmon (``).

              Helped-by: Jeff King (peff).
              (Merged by Junio C Hamano -- gitster -- in commit a5ab66e, 06 Nov 2018)




              archive: initialize archivers earlier



              Initialize archivers as soon as possible when running git archive.

              Various non-obvious behavior depends on having the archivers initialized, such as determining the desired archival format from the provided filename.



              Since 08716b3 ("archive: refactor file extension format-guessing",
              2011-06-21, Git v1.7.7-rc0), archive_format_from_filename() has used the registered
              archivers to match filenames (provided via --output) to archival
              formats.



              However, when git archive is executed with --remote, format detection happens before the archivers have been registered.

              This causes archives from remotes to always be generated as TAR files, regardless of
              the actual filename (unless an explicit --format is provided).



              This patch fixes that behavior; archival format is determined properly
              from the output filename, even when --remote is used.







              share|improve this answer























                up vote
                0
                down vote










                up vote
                0
                down vote









                In addition of CharlesB's script, make sure yo use Git 2.20+ (Q4 201), because git archive -o latest_${branch}_${sha1}.zip can produce a tar file instead of a zip one (bug which has been fixed), if use for a --remote repo.



                See commit 00436bf (25 Oct 2018) by Josh Steadmon (``).

                Helped-by: Jeff King (peff).
                (Merged by Junio C Hamano -- gitster -- in commit a5ab66e, 06 Nov 2018)




                archive: initialize archivers earlier



                Initialize archivers as soon as possible when running git archive.

                Various non-obvious behavior depends on having the archivers initialized, such as determining the desired archival format from the provided filename.



                Since 08716b3 ("archive: refactor file extension format-guessing",
                2011-06-21, Git v1.7.7-rc0), archive_format_from_filename() has used the registered
                archivers to match filenames (provided via --output) to archival
                formats.



                However, when git archive is executed with --remote, format detection happens before the archivers have been registered.

                This causes archives from remotes to always be generated as TAR files, regardless of
                the actual filename (unless an explicit --format is provided).



                This patch fixes that behavior; archival format is determined properly
                from the output filename, even when --remote is used.







                share|improve this answer












                In addition of CharlesB's script, make sure yo use Git 2.20+ (Q4 201), because git archive -o latest_${branch}_${sha1}.zip can produce a tar file instead of a zip one (bug which has been fixed), if use for a --remote repo.



                See commit 00436bf (25 Oct 2018) by Josh Steadmon (``).

                Helped-by: Jeff King (peff).
                (Merged by Junio C Hamano -- gitster -- in commit a5ab66e, 06 Nov 2018)




                archive: initialize archivers earlier



                Initialize archivers as soon as possible when running git archive.

                Various non-obvious behavior depends on having the archivers initialized, such as determining the desired archival format from the provided filename.



                Since 08716b3 ("archive: refactor file extension format-guessing",
                2011-06-21, Git v1.7.7-rc0), archive_format_from_filename() has used the registered
                archivers to match filenames (provided via --output) to archival
                formats.



                However, when git archive is executed with --remote, format detection happens before the archivers have been registered.

                This causes archives from remotes to always be generated as TAR files, regardless of
                the actual filename (unless an explicit --format is provided).



                This patch fixes that behavior; archival format is determined properly
                from the output filename, even when --remote is used.








                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Nov 11 at 1:43









                VonC

                821k28425803095




                821k28425803095






























                     

                    draft saved


                    draft discarded



















































                     


                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function () {
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f14985956%2fhow-to-append-branch-name-and-commit-to-git-archive-output-file%23new-answer', 'question_page');
                    }
                    );

                    Post as a guest















                    Required, but never shown





















































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown

































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown







                    Popular posts from this blog

                    Xamarin.iOS Cant Deploy on Iphone

                    Glorious Revolution

                    Dulmage-Mendelsohn matrix decomposition in Python