Skip to content

Commit 89ed85e

Browse files
committed
Merge pull request #479 from crd/attributes_consistency
Update Ch8 to refer to .gitattributes consistently
2 parents ee162f0 + 6a7338f commit 89ed85e

File tree

1 file changed

+31
-9
lines changed

1 file changed

+31
-9
lines changed

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

Lines changed: 31 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -111,11 +111,18 @@ It's not perfect – formatting changes wouldn't show up here – but it certain
111111

112112
Another interesting problem you can solve this way involves diffing image files.
113113
One way to do this is to run image files through a filter that extracts their EXIF information – metadata that is recorded with most image formats.
114-
If you download and install the `exiftool` program, you can use it to convert your images into text about the metadata, so at least the diff will show you a textual representation of any changes that happened:
114+
If you download and install the `exiftool` program, you can use it to convert your images into text about the metadata, so at least the diff will show you a textual representation of any changes that happened.
115+
Put the following line in your `.gitattributes` file:
116+
117+
[source,ini]
118+
----
119+
*.png diff=exif
120+
----
121+
122+
Configure Git to use this tool:
115123

116124
[source,console]
117125
----
118-
$ echo '*.png diff=exif' >> .gitattributes
119126
$ git config diff.exif.textconv exiftool
120127
----
121128

@@ -156,11 +163,18 @@ Git attributes offers you two ways to do this.
156163

157164
First, you can inject the SHA-1 checksum of a blob into an `$Id$` field in the file automatically.
158165
If you set this attribute on a file or set of files, then the next time you check out that branch, Git will replace that field with the SHA-1 of the blob.
159-
It's important to notice that it isn't the SHA-1 of the commit, but of the blob itself:
166+
It's important to notice that it isn't the SHA-1 of the commit, but of the blob itself.
167+
Put the following line in your `.gitattributes` file:
168+
169+
[source,ini]
170+
----
171+
*.txt ident
172+
----
173+
174+
Add an `$Id$` reference to a test file:
160175

161176
[source,console]
162177
----
163-
$ echo '*.txt ident' >> .gitattributes
164178
$ echo '$Id$' > test.txt
165179
----
166180

@@ -234,12 +248,16 @@ $ git config filter.dater.clean 'perl -pe "s/\\\$Date[^\\\$]*\\\$/\\\$Date\\\$/"
234248
----
235249

236250
This Perl snippet strips out anything it sees in a `$Date$` string, to get back to where you started.
237-
Now that your filter is ready, you can test it by setting up a file with your `$Date$` keyword and then setting up a Git attribute for that file that engages the new filter:
251+
Now that your filter is ready, you can test it by setting up a Git attribute for that file that engages the new filter and creating a file with your `$Date$` keyword:
252+
253+
[source,ini]
254+
----
255+
date*.txt filter=dater
256+
----
238257

239258
[source,console]
240259
----
241260
$ echo '# $Date$' > date_test.txt
242-
$ echo 'date*.txt filter=dater' >> .gitattributes
243261
----
244262

245263
If you commit those changes and check out the file again, you see the keyword properly substituted:
@@ -283,12 +301,16 @@ Now, when you run git archive to create a tarball of your project, that director
283301
When exporting files for deployment you can apply `git log`'s formatting and keyword-expansion processing to selected portions of files marked with the
284302
`export-subst` attribute.
285303

286-
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:
304+
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 your `.gitattributes` and `LAST_COMMIT` files like this:
305+
306+
[source,ini]
307+
----
308+
LAST_COMMIT export-subst
309+
----
287310

288311
[source,console]
289312
----
290313
$ echo 'Last commit date: $Format:%cd by %aN$' > LAST_COMMIT
291-
$ echo "LAST_COMMIT export-subst" >> .gitattributes
292314
$ git add LAST_COMMIT .gitattributes
293315
$ git commit -am 'adding LAST_COMMIT file for archives'
294316
----
@@ -317,7 +339,7 @@ $ git archive @ | tar xfO - LAST_COMMIT
317339
Last commit: 312ccc8 by Jim Hill at Fri May 8 09:14:04 2015 -0700
318340
export-subst uses git log's custom formatter
319341
320-
git archive uses git log's `pretty=format:` processor directly, and
342+
git archive uses git log's `pretty=format:` processor directly, and
321343
strips the surrounding `$Format:` and `$` markup from the output.
322344
----
323345

0 commit comments

Comments
 (0)