Git keyword expansionΒΆ

We can archive the files using keywords defined in gitattributes by using the command git archive.

We archive files by:

git archive --format=tgz --worktree-attributes HEAD file1 file2 ...

The attributes are taken from the tree, and with the option --worktree-attributes in the checked out worktree.

Git also look at the repository local file $GIT_DIR/info/attributes

If the attribute export-subst is set for a file then git will expand several placeholders with the syntax $Format:PLACEHOLDERS$.

The place holders are defined in git log pretty formats

I use in my C source files:

/* @date   $Format: %ci$
 * @version Commit: $Format: %h$
 * Tree: $Format: %t$

To exports the committer date %ci, the abbreviated tree hash <%t, and the abbreviated commit hash %h