How to include the current Git commit ID and branch in my document?

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP











up vote
5
down vote

favorite
2












I use Git to track changes on my TEX files. When producing a PDF, it would be nice to include the current branch and commit ID somewhere in the document (e.g. on the title page or in a footer).



I know that the package gitinfo2 exists but I'd rather avoid adding any hooks to Git. Besides, I am aware of this question but I would prefer a solution that does not require enabling write18.



Given that the name of the current branch can be found in .git/HEAD and the current commit ID is stored in .git/refs/heads/[name of branch], is it possible to embed this information in the final document?










share|improve this question























  • I'm writing this self-answered Q&A because it took me a while to figure this out. Hope it will help others in the future.
    – CL.
    3 hours ago










  • despite the question saying you wanted an alternative to gitinfo, there is a big overlap so I added that tag
    – David Carlisle
    3 hours ago














up vote
5
down vote

favorite
2












I use Git to track changes on my TEX files. When producing a PDF, it would be nice to include the current branch and commit ID somewhere in the document (e.g. on the title page or in a footer).



I know that the package gitinfo2 exists but I'd rather avoid adding any hooks to Git. Besides, I am aware of this question but I would prefer a solution that does not require enabling write18.



Given that the name of the current branch can be found in .git/HEAD and the current commit ID is stored in .git/refs/heads/[name of branch], is it possible to embed this information in the final document?










share|improve this question























  • I'm writing this self-answered Q&A because it took me a while to figure this out. Hope it will help others in the future.
    – CL.
    3 hours ago










  • despite the question saying you wanted an alternative to gitinfo, there is a big overlap so I added that tag
    – David Carlisle
    3 hours ago












up vote
5
down vote

favorite
2









up vote
5
down vote

favorite
2






2





I use Git to track changes on my TEX files. When producing a PDF, it would be nice to include the current branch and commit ID somewhere in the document (e.g. on the title page or in a footer).



I know that the package gitinfo2 exists but I'd rather avoid adding any hooks to Git. Besides, I am aware of this question but I would prefer a solution that does not require enabling write18.



Given that the name of the current branch can be found in .git/HEAD and the current commit ID is stored in .git/refs/heads/[name of branch], is it possible to embed this information in the final document?










share|improve this question















I use Git to track changes on my TEX files. When producing a PDF, it would be nice to include the current branch and commit ID somewhere in the document (e.g. on the title page or in a footer).



I know that the package gitinfo2 exists but I'd rather avoid adding any hooks to Git. Besides, I am aware of this question but I would prefer a solution that does not require enabling write18.



Given that the name of the current branch can be found in .git/HEAD and the current commit ID is stored in .git/refs/heads/[name of branch], is it possible to embed this information in the final document?







revision-control git gitinfo






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited 3 hours ago









David Carlisle

472k3811001829




472k3811001829










asked 3 hours ago









CL.

320114




320114











  • I'm writing this self-answered Q&A because it took me a while to figure this out. Hope it will help others in the future.
    – CL.
    3 hours ago










  • despite the question saying you wanted an alternative to gitinfo, there is a big overlap so I added that tag
    – David Carlisle
    3 hours ago
















  • I'm writing this self-answered Q&A because it took me a while to figure this out. Hope it will help others in the future.
    – CL.
    3 hours ago










  • despite the question saying you wanted an alternative to gitinfo, there is a big overlap so I added that tag
    – David Carlisle
    3 hours ago















I'm writing this self-answered Q&A because it took me a while to figure this out. Hope it will help others in the future.
– CL.
3 hours ago




I'm writing this self-answered Q&A because it took me a while to figure this out. Hope it will help others in the future.
– CL.
3 hours ago












despite the question saying you wanted an alternative to gitinfo, there is a big overlap so I added that tag
– David Carlisle
3 hours ago




despite the question saying you wanted an alternative to gitinfo, there is a big overlap so I added that tag
– David Carlisle
3 hours ago










2 Answers
2






active

oldest

votes

















up vote
5
down vote













As stated in the question, the branch name can be extracted from .git/HEAD and given [branch name], the commit ID can be found in .git/refs/heads/[branch name].



The package catchfile provides the command CatchFileDef, which allows us to read .git/HEAD into a macro. As HEAD has no file extension, MiKTeX users have to add a trailing dot to the file name:



CatchFileDefheadfull.git/HEAD.


This assigns something like ref: refs/heads/master to headfull. As this string has a trailing whitespace character, we use StrGobbleRight from the xstring package to trim it:1



StrGobbleRightheadfull1[head]


In order to extract only the branch name (master in the example) from this string, we can use StrBehind:



StrBehind[2]head/[branch]


This saves the branch name in branch. Finally, we can use CatchFileDef again, to save the commit ID in commit:



CatchFileDefcommit.git/refs/heads/branch.


Full MWE:



documentclassarticle

usepackagexstring
usepackagecatchfile

CatchFileDefheadfull.git/HEAD.
StrGobbleRightheadfull1[head]
StrBehind[2]head/[branch]
CatchFileDefcommit.git/refs/heads/branch.

begindocument
This revision: textttcommit on branch textttbranch.
enddocument


Sample output:




This revision: d92dc1386e48e04ceecb85461ed3b232146e6a32 on branch
master.





1 Using the last optional argument of StrGobbleRight (name) to assign the trimmed string to a macro (head) is necessary to allow further manipulation of the string using the xstring functions – see here for a discussion.






share|improve this answer



























    up vote
    5
    down vote













    A no-package approach (tested on mac os, modify it for Windows regarding extra needed dot perhaps) based on @CL.'s answer.



    documentclassarticle

    newcommanddotGitHEAD
    newcommandbranch
    newcommandcommit


    makeatletterletmyfilehandle@inputcheckmakeatother

    openinmyfilehandle=.git/HEADrelax

    begingroupendlinechar-1
    globalreadmyfilehandle to dotGitHEAD
    endgroup
    closeinmyfilehandle

    newcommandGetBranch
    defGetBranch ref: refs/heads/#1relaxrenewcommandbranch#1

    expandafterGetBranchdotGitHEADrelax

    openinmyfilehandle=.git/refs/heads/branchrelax

    begingroupendlinechar-1
    globalreadmyfilehandle to commit
    endgroup
    closeinmyfilehandle

    begindocument
    branch+++

    commit+++

    This revision: textttcommit on branch textttbranch.
    enddocument


    enter image description here





    Package getcommit:



    ProvidesPackagegetcommit[2018/10/16 get current commit and branch (JFB)]

    @ifundefinedbranch
    PackageWarninggetcommitATTENTION!^^J
    @spaces@spacesstringbranchspace macro was already
    defined. Overwritten.
    @ifundefinedcommit
    PackageWarninggetcommitATTENTION!^^J
    @spaces@spacesstringcommitspace macro was already
    defined. Overwritten.

    openin@inputcheck=.git/HEADrelax

    begingroupendlinechar-1
    globalread@inputcheck to getcommit@HEAD
    endgroup
    closein@inputcheck

    defgetcommit@GetBranch ref: refs/heads/#1relaxdefbranch#1

    expandaftergetcommit@GetBranchgetcommit@HEADrelax

    openin@inputcheck=.git/refs/heads/branchrelax

    begingroupendlinechar-1
    globalread@inputcheck to commit
    endgroup
    closein@inputcheck
    endinput


    Example of use:



    documentclassarticle

    usepackagegetcommit

    begindocument
    +++branch+++

    +++commit+++

    %frenchspacing
    This revision: textttcommit on branch textttbranch.
    enddocument





    share|improve this answer






















    • is there an available scratch file handle for read operations in LaTeX, avoiding a newread here?
      – jfbu
      2 hours ago






    • 1




      There is @inputcheck used by the kernel in IfFileExists.
      – Ulrike Fischer
      2 hours ago










    • Quite nice and it works on windows. But imho for a real package it should try to find the info also in parent folders (imho gitinfo2 looks 4 levels up by default).
      – Ulrike Fischer
      50 mins ago










    • But miktex really needs the period at the end ...
      – Ulrike Fischer
      41 mins ago










    • @UlrikeFischer is there any test allowing package to know that this is executed under MikTeX?
      – jfbu
      30 mins ago










    Your Answer







    StackExchange.ready(function()
    var channelOptions =
    tags: "".split(" "),
    id: "85"
    ;
    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: false,
    noModals: false,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: null,
    bindNavPrevention: true,
    postfix: "",
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    );



    );













     

    draft saved


    draft discarded


















    StackExchange.ready(
    function ()
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2ftex.stackexchange.com%2fquestions%2f455396%2fhow-to-include-the-current-git-commit-id-and-branch-in-my-document%23new-answer', 'question_page');

    );

    Post as a guest






























    2 Answers
    2






    active

    oldest

    votes








    2 Answers
    2






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes








    up vote
    5
    down vote













    As stated in the question, the branch name can be extracted from .git/HEAD and given [branch name], the commit ID can be found in .git/refs/heads/[branch name].



    The package catchfile provides the command CatchFileDef, which allows us to read .git/HEAD into a macro. As HEAD has no file extension, MiKTeX users have to add a trailing dot to the file name:



    CatchFileDefheadfull.git/HEAD.


    This assigns something like ref: refs/heads/master to headfull. As this string has a trailing whitespace character, we use StrGobbleRight from the xstring package to trim it:1



    StrGobbleRightheadfull1[head]


    In order to extract only the branch name (master in the example) from this string, we can use StrBehind:



    StrBehind[2]head/[branch]


    This saves the branch name in branch. Finally, we can use CatchFileDef again, to save the commit ID in commit:



    CatchFileDefcommit.git/refs/heads/branch.


    Full MWE:



    documentclassarticle

    usepackagexstring
    usepackagecatchfile

    CatchFileDefheadfull.git/HEAD.
    StrGobbleRightheadfull1[head]
    StrBehind[2]head/[branch]
    CatchFileDefcommit.git/refs/heads/branch.

    begindocument
    This revision: textttcommit on branch textttbranch.
    enddocument


    Sample output:




    This revision: d92dc1386e48e04ceecb85461ed3b232146e6a32 on branch
    master.





    1 Using the last optional argument of StrGobbleRight (name) to assign the trimmed string to a macro (head) is necessary to allow further manipulation of the string using the xstring functions – see here for a discussion.






    share|improve this answer
























      up vote
      5
      down vote













      As stated in the question, the branch name can be extracted from .git/HEAD and given [branch name], the commit ID can be found in .git/refs/heads/[branch name].



      The package catchfile provides the command CatchFileDef, which allows us to read .git/HEAD into a macro. As HEAD has no file extension, MiKTeX users have to add a trailing dot to the file name:



      CatchFileDefheadfull.git/HEAD.


      This assigns something like ref: refs/heads/master to headfull. As this string has a trailing whitespace character, we use StrGobbleRight from the xstring package to trim it:1



      StrGobbleRightheadfull1[head]


      In order to extract only the branch name (master in the example) from this string, we can use StrBehind:



      StrBehind[2]head/[branch]


      This saves the branch name in branch. Finally, we can use CatchFileDef again, to save the commit ID in commit:



      CatchFileDefcommit.git/refs/heads/branch.


      Full MWE:



      documentclassarticle

      usepackagexstring
      usepackagecatchfile

      CatchFileDefheadfull.git/HEAD.
      StrGobbleRightheadfull1[head]
      StrBehind[2]head/[branch]
      CatchFileDefcommit.git/refs/heads/branch.

      begindocument
      This revision: textttcommit on branch textttbranch.
      enddocument


      Sample output:




      This revision: d92dc1386e48e04ceecb85461ed3b232146e6a32 on branch
      master.





      1 Using the last optional argument of StrGobbleRight (name) to assign the trimmed string to a macro (head) is necessary to allow further manipulation of the string using the xstring functions – see here for a discussion.






      share|improve this answer






















        up vote
        5
        down vote










        up vote
        5
        down vote









        As stated in the question, the branch name can be extracted from .git/HEAD and given [branch name], the commit ID can be found in .git/refs/heads/[branch name].



        The package catchfile provides the command CatchFileDef, which allows us to read .git/HEAD into a macro. As HEAD has no file extension, MiKTeX users have to add a trailing dot to the file name:



        CatchFileDefheadfull.git/HEAD.


        This assigns something like ref: refs/heads/master to headfull. As this string has a trailing whitespace character, we use StrGobbleRight from the xstring package to trim it:1



        StrGobbleRightheadfull1[head]


        In order to extract only the branch name (master in the example) from this string, we can use StrBehind:



        StrBehind[2]head/[branch]


        This saves the branch name in branch. Finally, we can use CatchFileDef again, to save the commit ID in commit:



        CatchFileDefcommit.git/refs/heads/branch.


        Full MWE:



        documentclassarticle

        usepackagexstring
        usepackagecatchfile

        CatchFileDefheadfull.git/HEAD.
        StrGobbleRightheadfull1[head]
        StrBehind[2]head/[branch]
        CatchFileDefcommit.git/refs/heads/branch.

        begindocument
        This revision: textttcommit on branch textttbranch.
        enddocument


        Sample output:




        This revision: d92dc1386e48e04ceecb85461ed3b232146e6a32 on branch
        master.





        1 Using the last optional argument of StrGobbleRight (name) to assign the trimmed string to a macro (head) is necessary to allow further manipulation of the string using the xstring functions – see here for a discussion.






        share|improve this answer












        As stated in the question, the branch name can be extracted from .git/HEAD and given [branch name], the commit ID can be found in .git/refs/heads/[branch name].



        The package catchfile provides the command CatchFileDef, which allows us to read .git/HEAD into a macro. As HEAD has no file extension, MiKTeX users have to add a trailing dot to the file name:



        CatchFileDefheadfull.git/HEAD.


        This assigns something like ref: refs/heads/master to headfull. As this string has a trailing whitespace character, we use StrGobbleRight from the xstring package to trim it:1



        StrGobbleRightheadfull1[head]


        In order to extract only the branch name (master in the example) from this string, we can use StrBehind:



        StrBehind[2]head/[branch]


        This saves the branch name in branch. Finally, we can use CatchFileDef again, to save the commit ID in commit:



        CatchFileDefcommit.git/refs/heads/branch.


        Full MWE:



        documentclassarticle

        usepackagexstring
        usepackagecatchfile

        CatchFileDefheadfull.git/HEAD.
        StrGobbleRightheadfull1[head]
        StrBehind[2]head/[branch]
        CatchFileDefcommit.git/refs/heads/branch.

        begindocument
        This revision: textttcommit on branch textttbranch.
        enddocument


        Sample output:




        This revision: d92dc1386e48e04ceecb85461ed3b232146e6a32 on branch
        master.





        1 Using the last optional argument of StrGobbleRight (name) to assign the trimmed string to a macro (head) is necessary to allow further manipulation of the string using the xstring functions – see here for a discussion.







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered 3 hours ago









        CL.

        320114




        320114




















            up vote
            5
            down vote













            A no-package approach (tested on mac os, modify it for Windows regarding extra needed dot perhaps) based on @CL.'s answer.



            documentclassarticle

            newcommanddotGitHEAD
            newcommandbranch
            newcommandcommit


            makeatletterletmyfilehandle@inputcheckmakeatother

            openinmyfilehandle=.git/HEADrelax

            begingroupendlinechar-1
            globalreadmyfilehandle to dotGitHEAD
            endgroup
            closeinmyfilehandle

            newcommandGetBranch
            defGetBranch ref: refs/heads/#1relaxrenewcommandbranch#1

            expandafterGetBranchdotGitHEADrelax

            openinmyfilehandle=.git/refs/heads/branchrelax

            begingroupendlinechar-1
            globalreadmyfilehandle to commit
            endgroup
            closeinmyfilehandle

            begindocument
            branch+++

            commit+++

            This revision: textttcommit on branch textttbranch.
            enddocument


            enter image description here





            Package getcommit:



            ProvidesPackagegetcommit[2018/10/16 get current commit and branch (JFB)]

            @ifundefinedbranch
            PackageWarninggetcommitATTENTION!^^J
            @spaces@spacesstringbranchspace macro was already
            defined. Overwritten.
            @ifundefinedcommit
            PackageWarninggetcommitATTENTION!^^J
            @spaces@spacesstringcommitspace macro was already
            defined. Overwritten.

            openin@inputcheck=.git/HEADrelax

            begingroupendlinechar-1
            globalread@inputcheck to getcommit@HEAD
            endgroup
            closein@inputcheck

            defgetcommit@GetBranch ref: refs/heads/#1relaxdefbranch#1

            expandaftergetcommit@GetBranchgetcommit@HEADrelax

            openin@inputcheck=.git/refs/heads/branchrelax

            begingroupendlinechar-1
            globalread@inputcheck to commit
            endgroup
            closein@inputcheck
            endinput


            Example of use:



            documentclassarticle

            usepackagegetcommit

            begindocument
            +++branch+++

            +++commit+++

            %frenchspacing
            This revision: textttcommit on branch textttbranch.
            enddocument





            share|improve this answer






















            • is there an available scratch file handle for read operations in LaTeX, avoiding a newread here?
              – jfbu
              2 hours ago






            • 1




              There is @inputcheck used by the kernel in IfFileExists.
              – Ulrike Fischer
              2 hours ago










            • Quite nice and it works on windows. But imho for a real package it should try to find the info also in parent folders (imho gitinfo2 looks 4 levels up by default).
              – Ulrike Fischer
              50 mins ago










            • But miktex really needs the period at the end ...
              – Ulrike Fischer
              41 mins ago










            • @UlrikeFischer is there any test allowing package to know that this is executed under MikTeX?
              – jfbu
              30 mins ago














            up vote
            5
            down vote













            A no-package approach (tested on mac os, modify it for Windows regarding extra needed dot perhaps) based on @CL.'s answer.



            documentclassarticle

            newcommanddotGitHEAD
            newcommandbranch
            newcommandcommit


            makeatletterletmyfilehandle@inputcheckmakeatother

            openinmyfilehandle=.git/HEADrelax

            begingroupendlinechar-1
            globalreadmyfilehandle to dotGitHEAD
            endgroup
            closeinmyfilehandle

            newcommandGetBranch
            defGetBranch ref: refs/heads/#1relaxrenewcommandbranch#1

            expandafterGetBranchdotGitHEADrelax

            openinmyfilehandle=.git/refs/heads/branchrelax

            begingroupendlinechar-1
            globalreadmyfilehandle to commit
            endgroup
            closeinmyfilehandle

            begindocument
            branch+++

            commit+++

            This revision: textttcommit on branch textttbranch.
            enddocument


            enter image description here





            Package getcommit:



            ProvidesPackagegetcommit[2018/10/16 get current commit and branch (JFB)]

            @ifundefinedbranch
            PackageWarninggetcommitATTENTION!^^J
            @spaces@spacesstringbranchspace macro was already
            defined. Overwritten.
            @ifundefinedcommit
            PackageWarninggetcommitATTENTION!^^J
            @spaces@spacesstringcommitspace macro was already
            defined. Overwritten.

            openin@inputcheck=.git/HEADrelax

            begingroupendlinechar-1
            globalread@inputcheck to getcommit@HEAD
            endgroup
            closein@inputcheck

            defgetcommit@GetBranch ref: refs/heads/#1relaxdefbranch#1

            expandaftergetcommit@GetBranchgetcommit@HEADrelax

            openin@inputcheck=.git/refs/heads/branchrelax

            begingroupendlinechar-1
            globalread@inputcheck to commit
            endgroup
            closein@inputcheck
            endinput


            Example of use:



            documentclassarticle

            usepackagegetcommit

            begindocument
            +++branch+++

            +++commit+++

            %frenchspacing
            This revision: textttcommit on branch textttbranch.
            enddocument





            share|improve this answer






















            • is there an available scratch file handle for read operations in LaTeX, avoiding a newread here?
              – jfbu
              2 hours ago






            • 1




              There is @inputcheck used by the kernel in IfFileExists.
              – Ulrike Fischer
              2 hours ago










            • Quite nice and it works on windows. But imho for a real package it should try to find the info also in parent folders (imho gitinfo2 looks 4 levels up by default).
              – Ulrike Fischer
              50 mins ago










            • But miktex really needs the period at the end ...
              – Ulrike Fischer
              41 mins ago










            • @UlrikeFischer is there any test allowing package to know that this is executed under MikTeX?
              – jfbu
              30 mins ago












            up vote
            5
            down vote










            up vote
            5
            down vote









            A no-package approach (tested on mac os, modify it for Windows regarding extra needed dot perhaps) based on @CL.'s answer.



            documentclassarticle

            newcommanddotGitHEAD
            newcommandbranch
            newcommandcommit


            makeatletterletmyfilehandle@inputcheckmakeatother

            openinmyfilehandle=.git/HEADrelax

            begingroupendlinechar-1
            globalreadmyfilehandle to dotGitHEAD
            endgroup
            closeinmyfilehandle

            newcommandGetBranch
            defGetBranch ref: refs/heads/#1relaxrenewcommandbranch#1

            expandafterGetBranchdotGitHEADrelax

            openinmyfilehandle=.git/refs/heads/branchrelax

            begingroupendlinechar-1
            globalreadmyfilehandle to commit
            endgroup
            closeinmyfilehandle

            begindocument
            branch+++

            commit+++

            This revision: textttcommit on branch textttbranch.
            enddocument


            enter image description here





            Package getcommit:



            ProvidesPackagegetcommit[2018/10/16 get current commit and branch (JFB)]

            @ifundefinedbranch
            PackageWarninggetcommitATTENTION!^^J
            @spaces@spacesstringbranchspace macro was already
            defined. Overwritten.
            @ifundefinedcommit
            PackageWarninggetcommitATTENTION!^^J
            @spaces@spacesstringcommitspace macro was already
            defined. Overwritten.

            openin@inputcheck=.git/HEADrelax

            begingroupendlinechar-1
            globalread@inputcheck to getcommit@HEAD
            endgroup
            closein@inputcheck

            defgetcommit@GetBranch ref: refs/heads/#1relaxdefbranch#1

            expandaftergetcommit@GetBranchgetcommit@HEADrelax

            openin@inputcheck=.git/refs/heads/branchrelax

            begingroupendlinechar-1
            globalread@inputcheck to commit
            endgroup
            closein@inputcheck
            endinput


            Example of use:



            documentclassarticle

            usepackagegetcommit

            begindocument
            +++branch+++

            +++commit+++

            %frenchspacing
            This revision: textttcommit on branch textttbranch.
            enddocument





            share|improve this answer














            A no-package approach (tested on mac os, modify it for Windows regarding extra needed dot perhaps) based on @CL.'s answer.



            documentclassarticle

            newcommanddotGitHEAD
            newcommandbranch
            newcommandcommit


            makeatletterletmyfilehandle@inputcheckmakeatother

            openinmyfilehandle=.git/HEADrelax

            begingroupendlinechar-1
            globalreadmyfilehandle to dotGitHEAD
            endgroup
            closeinmyfilehandle

            newcommandGetBranch
            defGetBranch ref: refs/heads/#1relaxrenewcommandbranch#1

            expandafterGetBranchdotGitHEADrelax

            openinmyfilehandle=.git/refs/heads/branchrelax

            begingroupendlinechar-1
            globalreadmyfilehandle to commit
            endgroup
            closeinmyfilehandle

            begindocument
            branch+++

            commit+++

            This revision: textttcommit on branch textttbranch.
            enddocument


            enter image description here





            Package getcommit:



            ProvidesPackagegetcommit[2018/10/16 get current commit and branch (JFB)]

            @ifundefinedbranch
            PackageWarninggetcommitATTENTION!^^J
            @spaces@spacesstringbranchspace macro was already
            defined. Overwritten.
            @ifundefinedcommit
            PackageWarninggetcommitATTENTION!^^J
            @spaces@spacesstringcommitspace macro was already
            defined. Overwritten.

            openin@inputcheck=.git/HEADrelax

            begingroupendlinechar-1
            globalread@inputcheck to getcommit@HEAD
            endgroup
            closein@inputcheck

            defgetcommit@GetBranch ref: refs/heads/#1relaxdefbranch#1

            expandaftergetcommit@GetBranchgetcommit@HEADrelax

            openin@inputcheck=.git/refs/heads/branchrelax

            begingroupendlinechar-1
            globalread@inputcheck to commit
            endgroup
            closein@inputcheck
            endinput


            Example of use:



            documentclassarticle

            usepackagegetcommit

            begindocument
            +++branch+++

            +++commit+++

            %frenchspacing
            This revision: textttcommit on branch textttbranch.
            enddocument






            share|improve this answer














            share|improve this answer



            share|improve this answer








            edited 28 mins ago

























            answered 2 hours ago









            jfbu

            43.2k65141




            43.2k65141











            • is there an available scratch file handle for read operations in LaTeX, avoiding a newread here?
              – jfbu
              2 hours ago






            • 1




              There is @inputcheck used by the kernel in IfFileExists.
              – Ulrike Fischer
              2 hours ago










            • Quite nice and it works on windows. But imho for a real package it should try to find the info also in parent folders (imho gitinfo2 looks 4 levels up by default).
              – Ulrike Fischer
              50 mins ago










            • But miktex really needs the period at the end ...
              – Ulrike Fischer
              41 mins ago










            • @UlrikeFischer is there any test allowing package to know that this is executed under MikTeX?
              – jfbu
              30 mins ago
















            • is there an available scratch file handle for read operations in LaTeX, avoiding a newread here?
              – jfbu
              2 hours ago






            • 1




              There is @inputcheck used by the kernel in IfFileExists.
              – Ulrike Fischer
              2 hours ago










            • Quite nice and it works on windows. But imho for a real package it should try to find the info also in parent folders (imho gitinfo2 looks 4 levels up by default).
              – Ulrike Fischer
              50 mins ago










            • But miktex really needs the period at the end ...
              – Ulrike Fischer
              41 mins ago










            • @UlrikeFischer is there any test allowing package to know that this is executed under MikTeX?
              – jfbu
              30 mins ago















            is there an available scratch file handle for read operations in LaTeX, avoiding a newread here?
            – jfbu
            2 hours ago




            is there an available scratch file handle for read operations in LaTeX, avoiding a newread here?
            – jfbu
            2 hours ago




            1




            1




            There is @inputcheck used by the kernel in IfFileExists.
            – Ulrike Fischer
            2 hours ago




            There is @inputcheck used by the kernel in IfFileExists.
            – Ulrike Fischer
            2 hours ago












            Quite nice and it works on windows. But imho for a real package it should try to find the info also in parent folders (imho gitinfo2 looks 4 levels up by default).
            – Ulrike Fischer
            50 mins ago




            Quite nice and it works on windows. But imho for a real package it should try to find the info also in parent folders (imho gitinfo2 looks 4 levels up by default).
            – Ulrike Fischer
            50 mins ago












            But miktex really needs the period at the end ...
            – Ulrike Fischer
            41 mins ago




            But miktex really needs the period at the end ...
            – Ulrike Fischer
            41 mins ago












            @UlrikeFischer is there any test allowing package to know that this is executed under MikTeX?
            – jfbu
            30 mins ago




            @UlrikeFischer is there any test allowing package to know that this is executed under MikTeX?
            – jfbu
            30 mins ago

















             

            draft saved


            draft discarded















































             


            draft saved


            draft discarded














            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2ftex.stackexchange.com%2fquestions%2f455396%2fhow-to-include-the-current-git-commit-id-and-branch-in-my-document%23new-answer', 'question_page');

            );

            Post as a guest













































































            Comments

            Popular posts from this blog

            What does second last employer means? [closed]

            List of Gilmore Girls characters

            Confectionery