# Git export-subst

**URL:** <https://www.isharkfly.com/t/git-export-subst/10933>\
**Category:** 软件技术\
**Created:** [April 2, 2015, 12:22am UTC](https://www.isharkfly.com/t/git-export-subst/10933 "2015-04-02T00:22:48Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![honeymoose](https://www.isharkfly.com/user_avatar/www.isharkfly.com/honeymoose/32/20796_2.png) [@honeymoose](https://www.isharkfly.com/u/honeymoose)\
**Post date:** [April 2, 2015, 12:22am UTC](https://www.isharkfly.com/t/git-export-subst/10933/1 "2015-04-02T00:22:48Z")

</div>

还能对归档做一些简单的关键字替换。在第2章中已经可以看到，可以以–pretty=format形式的简码在任何文件中放入$Format: 字符串。例如，如果想在项目中包含一个叫作LAST\_COMMIT的文件，当运行git archive时，最后提交日期自动地注入进该文件，可以这样设置： echo ‘Last commit date: Format:%cd’ \> LAST\_COMMIT  
 echo "LAST\_COMMIT export-subst" \>\> .gitattributes git add LAST\_COMMIT .gitattributes  
$ git commit -am ‘adding LAST\_COMMIT file for archives’

运行git archive后，打开该文件，会发现其内容如下：

`$ cat LAST_COMMIT
Last commit date: $Format:Tue Apr 21 08:38:48 2009 -0700$`

REF：[http://cwiki.ossez.com/pages/viewpage.action?pageId=7045550](http://cwiki.ossez.com/pages/viewpage.action?pageId=7045550)
