File: git-lfs-faq.adoc

package info (click to toggle)
git-lfs 3.6.1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 4,808 kB
  • sloc: sh: 21,256; makefile: 507; ruby: 417
file content (285 lines) | stat: -rw-r--r-- 13,025 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
= git-lfs-faq(7)

== NAME

git-lfs-faq - FAQ for Git LFS

== ENTRIES

[[cat-file-size]]
=== File Size

[[faq-track-by-size]]
Does Git LFS provide a way to track files by size?::
  No, it doesn't.  Unfortunately, Git itself doesn't specify a way to make
  `.gitattributes` patterns apply to files of a certain size and we rely on
  the `.gitattributes` file to specify which files are tracked by Git LFS.
+
You _can_ use the `--above` option to `git lfs migrate import` to migrate
all files that at the specified time are larger than a certain size.  However,
if your files change to be smaller or larger in the future, or you add more
files in the future that are larger than the limit you specified, you will have
to track them manually.
+
For these reasons, we recommend using patterns rather than `--above`.

[[faq-4gb-windows]]
Why doesn't Git LFS handle files larger than 4 GiB on Windows?::
  Git LFS itself handles these files just fine.  However, Git LFS is usually
  invoked by Git, and until Git 2.34, Git itself on Windows didn't handle files
  using smudge and clean filters (like Git LFS) that are larger than 4 GiB.
  So you can update Git for Windows to 2.34 to natively support these file sizes.
+
On older versions, set `GIT_LFS_SKIP_SMUDGE` to `1` and run `git lfs pull`
to pull down the LFS files.  This bypasses Git's smudging functionality
and therefore avoids its limitations.

[[cat-working-tree-contents]]
=== Working Tree Contents

[[faq-only-pointer-files]]
Why do I end up with small text files in my working tree instead of my files?::
  Git LFS stores small text files called pointer files in the repository instead
  of your large files, which it stores elsewhere.  These pointer files usually
  start with the line `version https://git-lfs.github.com/spec/v1`.
+
Normally, if you've run `git lfs install` at least once for your user account on
the system, then Git LFS will be automatically invoked by Git when you check out
files or clone a repository and this won't happen.  However, if you haven't, or
you've explicitly chosen to skip that behaviour by using the `--skip-smudge`
option of `git lfs install`, then you may need to use `git lfs pull` to replace
the pointer files in your working tree with large files.

[[faq-working-tree-modified]]
Why do I end up with some of my working tree files constantly showing as modified?::
  This can happen if someone made a commit to a file that's tracked by Git LFS
  but didn't have Git LFS properly set up on their system.  The objects that
  were checked into the repository are Git objects, not the pointers to Git LFS
  objects, and when Git checks these files out, it shows them as modified.
+
There are also several other possible ways to encounter this problem, such as an
incomplete migration of your repository.  For example, you should not use `git
lfs track` to track patterns that are already in your repository without running
`git add --renormalize .`, since that can lead to this problem.
+
Users frequently find that this cannot be changed by doing `git reset --hard` or
other techniques because Git then checks the files out and marks them as
modified again.  The best way to solve this problem is by fixing the files and
the committing the change, which you can do with the following on an otherwise
clean tree:
+
[source,shell-session]
----
$ git add --renormalize .
$ git commit -m "Fix broken LFS files"
----
+
This requires that every branch you want to fix have this done to it.
+
To prevent this from reoccurring in the future, make sure that everyone working
with large files on a project has run `git lfs install` at least once.  The
command `git lfs fsck --pointers BASE..HEAD` (with suitable values of `BASE` and
`HEAD`) may be used in your CI system to verify that nobody is introducing such
problems.

[[cat-tracking-and-migration]]
=== Tracking and Migration

[[faq-track-existing-files]]
How do I track files that are already in a repository?::
  If you want to track files that already exist in a repository, you need to do
  two things.  First, you need to use `git lfs track` (or a manual modification
  of `.gitattributes`) to mark the files as LFS files.  Then, you need to run
  `git add --renormalize .` and commit the changes to the repository.
+
If you skip this second step, then you'll end up with files that are marked as
LFS files but are stored as Git files, which can lead to files which are always
modified, as outlined in the FAQ entry above.  Note also that this doesn't
change large files in your history.  To do that, use `git lfs migrate import
--everything` instead, as specified in one of the entries below.

[[faq-export-to-git]]
How do I convert from using Git LFS to a plain Git repository?::
  If you'd like to stop using Git LFS and switch back to storing your large
  files in the plain Git format, you can do so with `git lfs migrate export
  --everything`.  Note that you will need to provide an appropriate `--include`
  option to match all the patterns that you currently have tracked in any ref.
+
This also rewrites history, so the Git object IDs of many, if not all, of your
objects will change.

[[faq-github-large-files]]
I'm using Git LFS, but I still see GitHub's large file error.  How do I fix this?::
  GitHub rejects large files anywhere in the history of your repository, not
  just in the latest commit.  If you're still seeing this message, then you have
  some large files somewhere in your history, even if in the latest commits
  you've moved them to Git LFS.
+
To fix this, you can use `git lfs migrate import --everything` with an
appropriate `--include` argument.  For example, if you wanted to move your
`.jpg` and `.png` files into Git LFS, you can do that with
`git lfs migrate import --everything --include="\*.jpg,*.png"`.  More complicated
patterns are possible: run `git help gitattributes` for more information on
valid patterns.  Note that if you're specifying directories, using slashes is
mandatory: backslashes are not allowed as path separators.

[[cat-configuration]]
=== Configuration

[[faq-proxy]]
Can I use a proxy with Git LFS?::
  Yes, Git LFS supports proxies using the same mechanisms that Git supports,
  namely the `http_proxy` environment variable and the configuration of
  `http.proxy` (or `http.*.proxy` for per-URL usage).  However, Git LFS only
  supports proxies which use Basic or no authentication, and it doesn't
  currently support Digest or Kerberos authentication.
+
If you're using a proxy, we recommend that you set the full URL in the proxy
value, including a scheme.  Thus, `http://example.com:3128` is a better choice
than `example.com:3128`.  If you need a username and password, they must be
percent-encoded in the URL, so a username of `foo\bar` with a password of
`abc@123+` using the above proxy would be
`http://foo%5cbar:abc%40123%2b@example.com:3128`.
+
Note that, just like with Git, proxies must not modify, buffer, tamper with, or
change the response to the data in any way, upstream or downstream, and any
proxy which does so will break things and is not supported. The Git LFS
developers don't recommend any sort of proxy, including any sort of antivirus,
firewall, or monitoring software, which performs TLS interception because these
are known to cause breakage and in general have been shown to worsen security.

[[faq-tls-ca]]
Can I use a custom set of SSL/TLS certificate authorities with Git LFS?::
  Yes, Git LFS supports configuring trusted certificate authorities and client
  certificates for HTTPS, using the same configuration as for Git.
+
To configure a set of trusted certificate authorities, you can use
`http.sslCAPath` to specify a directory of files, each one containing a PKCS#1
certificate of a trusted certificate authority.  If you'd prefer to use a single
file with all trusted certificates, you can use `http.sslCAInfo` to refer to a
single file containing PKCS#1 certificates, one following the other.
+
For example, on Debian, to set this option to provide the default behavior, you
could run `git config http.sslCAPath /etc/ssl/certs`.  Note that it's also
possible to set these configuration options on a per-URL basis, like so: `git
config http.https://example.com/.sslCAPath /etc/ssl/certs`.
+
Note that PKCS#12 files are a Git for Windows extension to Git and are not
supported by Git LFS.  Additionally, take into account the information about
TLS-intercepting proxies above if this configuration is because of a
TLS-intercepting proxy.

[[faq-tls-client-config]]
Can I use an SSL/TLS client certificate with Git LFS?::
  Yes, Git LFS supports configuring client certificates and keys using the same
  configuration as for Git.
+
To configure a client certificate, use the `http.sslCert` configuration option
pointing to a file containing a PKCS#1 certificate.  To configure the
corresponding key, use `http.sslKey` with a file containing a PEM-encoded key.
If it is encrypted, you will be prompted using the credential helper for the
passphrase.
+
Usually you will want to specify these values on a per-URL basis, such as the
following: `git config http.https://example.com/.sslKey
/home/user/.certs/mine.key`.
+
Note that PKCS#8 and PKCS#12 files are not supported by Git LFS.

[[cat-git-features]]
=== Working with Git Features

[[faq-git-diff-on-lfs]]
How do I enable git diff to work on LFS files?::
  You can run `git config diff.lfs.textconv cat`, which will produce normal
  diffs if your files are text files.

[[faq-git-diff-on-lfs-by-path]]
How do I enable git diff to work on LFS files based on extension or path?::
  If the above solution is too broad, each entry in the `.gitattributes` file
  can be customized by creating a custom global converter:
+
[source,shell-session]
----
$ git config --global diff.lfstext.textconv cat
----
+
Any given `.gitattributes` entry for large text files can be customized to use
  this global text converter (e.g., patch files), whereas binary formats can
  continue to use the conventional lfs diff tool, like so:
+
[source,shell-session]
----
$ cat .gitattributes
....
*.bin filter=lfs diff=lfs merge=lfs -text
*.patch filter=lfs diff=lfstext merge=lfs -text
....
----
+
Be advised that all developers sharing this repo with such a modified
`.gitattributes` file must have similarly configured the `lfstext` text
converter, whether globally or on a per repository basis.

[[faq-archive-subdirectory]]
Why are LFS files not included when I archive a subdirectory?::
  When you run `git archive` with only a subdirectory, such as `git archive
  HEAD:src`, Git resolves the revision (in this case, `HEAD:src`) to a tree, and
  only processes items in that tree.  Because the `.gitattributes` file is
  typically only in the root of the repository, Git doesn't even see that file,
  which controls whether files are considered LFS files, and hence doesn't
  consider any of the files in the directory as LFS files, and thus doesn't
  invoke Git LFS at all.
+
Since Git LFS doesn't even get invoked in this case, there's no way to change
how this works.  If you just want to include the single subdirectory without
stripping the prefix, you can do this: `git archive -o archive.tar.gz
--prefix=archive/ HEAD src`.  If you do want to strip the subdirectory name
(`src`) in this case, one option if you have the libarchive tar (available on Windows
and macOS as `tar`, and usually on Linux as `bsdtar`) is to do something like
this script:
+
[source,shell]
----
#!/bin/sh

# With trailing slash.
ARCHIVE_PREFIX="archive/"
# Without trailing slash.
SOURCE_PREFIX="src"
# Without directory or file components.
REVISION="HEAD"

temp=$(mktemp -d)

git archive --prefix="$ARCHIVE_PREFIX" "$REVISION" "$SOURCE_PREFIX" | bsdtar -C "$temp" -xf -
bsdtar -s "!^\./!$ARCHIVE_PREFIX!" --format=pax -czf archive.tar.gz -C "$temp/$ARCHIVE_PREFIX$SOURCE_PREFIX" .
rm -fr "$temp"
----

[[cat-non-git-tools]]
=== Working with Non-Git Tools

[[faq-jenkins-hooks]]
I'm using Jenkins and `git lfs install` fails due to an invalid hook path.  What do I do?::
  Recent versions of Jenkins have set `core.hooksPath` to various values,
  notably `NUL:` on Windows, with the goal of disabling hooks.  This is not a
  valid path on Windows, nor a valid value for this configuration option, so
  when `git lfs install` runs and Git LFS attempts to install hooks, the
  operation fails.
+
The easiest way to solve this problem is by using the `--skip-repo` option to
`git lfs install`, which skips the installation of the hooks.  Despite the name,
it can be successfully combined with `--local` if you need that option.
+
Note that this prevents things like `git push` from pushing LFS objects and
locked files from being read only, since those are implemented by hooks.  If you
need that functionality, you should review the Jenkins documentation about how
to properly configure the environment in such a situation so that hooks can be
used.

== SEE ALSO

git-config(1), git-lfs-install(1), gitattributes(5), gitignore(5).

Part of the git-lfs(1) suite.