Skip to content

Commit 1f73820

Browse files
committed
export-subst uses git log's custom formatter
git archive uses git log's `pretty=format:` processor directly, and strips the surrounding `$Format:` and `$` markup from the output.
1 parent 0c78194 commit 1f73820

File tree

1 file changed

+30
-7
lines changed

1 file changed

+30
-7
lines changed

book/08-customizing-git/sections/attributes.asc

Lines changed: 30 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -279,26 +279,49 @@ Now, when you run git archive to create a tarball of your project, that director
279279

280280
===== `export-subst`
281281

282-
Another thing you can do for your archives is some simple keyword substitution.
283-
Git lets you put the string `$Format:$` in any file with any of the `--pretty=format` formatting shortcodes, many of which you saw in Chapter 2.
284-
For instance, if you want to include a file named `LAST_COMMIT` in your project, and the last commit date was automatically injected into it when `git archive` ran, you can set up the file like this:
282+
When exporting files for deployment you can apply `git log`'s formatting and keyword-expansion processing to selected portions of files marked with the
283+
`export-subst` attribute.
284+
285+
For instance, if you want to include a file named `LAST_COMMIT` in your project, and have metadata about the last commit automatically injected into it when `git archive` runs, you can for example set up the file like this:
285286

286287
[source,console]
287288
----
288-
$ echo 'Last commit date: $Format:%cd$' > LAST_COMMIT
289+
$ echo 'Last commit date: $Format:%cd by %aN$' > LAST_COMMIT
289290
$ echo "LAST_COMMIT export-subst" >> .gitattributes
290291
$ git add LAST_COMMIT .gitattributes
291292
$ git commit -am 'adding LAST_COMMIT file for archives'
292293
----
293294

294-
When you run `git archive`, the contents of that file when people open the archive file will look like this:
295+
When you run `git archive`, the contents of the archived file will look like this:
295296

296297
[source,console]
297298
----
298-
$ cat LAST_COMMIT
299-
Last commit date: $Format:Tue Apr 21 08:38:48 2009 -0700$
299+
$ git archive HEAD | tar xCf ../deployment-testing -
300+
$ cat ../deployment-testing/LAST_COMMIT
301+
Last commit date: Tue Apr 21 08:38:48 2009 -0700 by Scott Chacon
302+
----
303+
304+
The substitutions can include for example the commit message and any git notes, and git log can do simple word wrapping:
305+
306+
[source.console]
307+
----
308+
$ echo '$Format:Last commit: %h by %aN at %cd%n%+w(76,6,9)%B$' > LAST_COMMIT
309+
$ git commit -am 'export-subst uses git log's custom formatter
310+
311+
git archive uses git log's `pretty=format:` processor
312+
directly, and strips the surrounding `$Format:` and `$`
313+
markup from the output.
314+
'
315+
$ git archive @ | tar xfO - LAST_COMMIT
316+
Last commit: 312ccc8 by Jim Hill at Fri May 8 09:14:04 2015 -0700
317+
export-subst uses git log's custom formatter
318+
319+
git archive uses git log's `pretty=format:` processor directly, and
320+
strips the surrounding `$Format:` and `$` markup from the output.
300321
----
301322

323+
The resulting archive is suitable for deployment work, but like any exported archive it isn't suitable for further development work.
324+
302325
==== Merge Strategies
303326

304327
(((merging, strategies)))

0 commit comments

Comments
 (0)