Add tag in “export-subst” file

Situation

We have a git workflow, where all release versions are stacked on the master branch, and when a commit is ready for deployment, we add a tag to it, then use git archive to build a bundle to be deployed.

  • Cloning git repo
  • Reading GIT Merge Markers
  • combining unrelated git repositories retaining history/branches
  • Jenkins job notification fails with “No git consumers for URI …”
  • Why does git merge with no conflicts still produce a merge commit?
  • Git - Save unfinished merge changes and checkout another branch
  • We use a version.txt file, marked in .gitattributes with the option export-subst, to keep track of which commit was used to build a given archive.

    Question

    If I write $Format:%d$ in version.txt, and export a tagged commit, I will have something like (HEAD, tag, master) written in the resulting file.

    How can I have the tag alone ?

    [edit] There is a git command which already produces that :

    git describe --tags HEAD
    

    This will output :

    latest_tag            #if HEAD is tagged
    
    latest_tag-5-g03cc91b #if HEAD is not tagged,
                          #and the latest tag is 5 commits ago on commit g03cc91b
    

    Is there some way to have a slug replaced with this output in version.txt ?

  • Pull from github without authentication every time
  • Troubles sharing my project from IntelliJ to GitHub (IntelliJ-GitHub permission denied, error= 13)
  • Copy a Bitbucket Repository from one account to another bitbucket account
  • Strange conflict on git
  • Committing and Pushing to GitHub using JGit - Bare Repo?
  • How do I get the effect of GNU tar's --strip-components with git-archive?
  • One Solution collect form web for “Add tag in “export-subst” file”

    You could use a content filter driver which would on git checkout automatically do the exact change you want.

    content filter river: smudge

    (From Pro Git book 7.2 Customizing Git – Git Attributes)

    You declare in a .gitattributes file a smudge script which will do the substitution for a special marker (that you want to be replaced with git describe --tags HEAD), without touching the other markers to be modified by export-subst on git archive.

    Then you call git archive, which should (not tested) replace the rest.

    Git Baby is a git and github fan, let's start git clone.