You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Update Ch8 to refer to .gitattributes consistently
All modifications to the .gitattributes file are now illustrated using
[source,ini] blocks. Previously it was a mishmash of [source,ini] and
[source,console] `echo foo >> .gitattributes` commands.
Copy file name to clipboardExpand all lines: book/08-customizing-git/sections/attributes.asc
+31-9Lines changed: 31 additions & 9 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -111,11 +111,18 @@ It's not perfect – formatting changes wouldn't show up here – but it certain
111
111
112
112
Another interesting problem you can solve this way involves diffing image files.
113
113
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:
115
123
116
124
[source,console]
117
125
----
118
-
$ echo '*.png diff=exif' >> .gitattributes
119
126
$ git config diff.exif.textconv exiftool
120
127
----
121
128
@@ -156,11 +163,18 @@ Git attributes offers you two ways to do this.
156
163
157
164
First, you can inject the SHA-1 checksum of a blob into an `$Id$` field in the file automatically.
158
165
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:
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
+
----
238
257
239
258
[source,console]
240
259
----
241
260
$ echo '# $Date$' > date_test.txt
242
-
$ echo 'date*.txt filter=dater' >> .gitattributes
243
261
----
244
262
245
263
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
283
301
When exporting files for deployment you can apply `git log`'s formatting and keyword-expansion processing to selected portions of files marked with the
284
302
`export-subst` attribute.
285
303
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
+
----
287
310
288
311
[source,console]
289
312
----
290
313
$ echo 'Last commit date: $Format:%cd by %aN$' > LAST_COMMIT
0 commit comments