Debian Codegraph @

docs/man/git-lfs-faq.adoc

raw
1 = git-lfs-faq(7)
2
3 == NAME
4
5 git-lfs-faq - FAQ for Git LFS
6
7 == ENTRIES
8
9 [[cat-file-size]]
10 === File Size
11
12 [[faq-track-by-size]]
13 Does Git LFS provide a way to track files by size?::
14 No, it doesn't. Unfortunately, Git itself doesn't specify a way to make
15 `.gitattributes` patterns apply to files of a certain size and we rely on
16 the `.gitattributes` file to specify which files are tracked by Git LFS.
17 +
18 You _can_ use the `--above` option to `git lfs migrate import` to migrate
19 all files that at the specified time are larger than a certain size. However,
20 if your files change to be smaller or larger in the future, or you add more
21 files in the future that are larger than the limit you specified, you will have
22 to track them manually.
23 +
24 For these reasons, we recommend using patterns rather than `--above`.
25
26 [[faq-4gb-windows]]
27 Why doesn't Git LFS handle files larger than 4 GiB on Windows?::
28 Git LFS itself handles these files just fine. However, Git LFS is usually
29 invoked by Git, and until Git 2.34, Git itself on Windows didn't handle files
30 using smudge and clean filters (like Git LFS) that are larger than 4 GiB.
31 So you can update Git for Windows to 2.34 to natively support these file sizes.
32 +
33 On older versions, set `GIT_LFS_SKIP_SMUDGE` to `1` and run `git lfs pull`
34 to pull down the LFS files. This bypasses Git's smudging functionality
35 and therefore avoids its limitations.
36
37 [[faq-git-memory-use]]
38 Why does cloning consume memory proportional to the largest Git LFS file?::
39 This is actually due to how Git smudges files and is not a consequence
40 of using Git LFS per se. As of the time of writing, all currently
41 available versions of Git (v2.51.2 and earlier) read the output of a
42 long-running filter process like Git LFS into in-memory buffers, one for
43 each file processed by the filter. As a result, when files are smudged
44 by Git LFS during a `git clone` operation, Git's memory usage scales with
45 the size of the largest Git LFS file.
46 +
47 Setting `GIT_LFS_SKIP_SMUDGE` to `1` when cloning and then running
48 `git lfs pull` to pull down the Git LFS files will bypass Git's smudging
49 functionality and avoid its limitations.
50
51 [[cat-working-tree-contents]]
52 === Working Tree Contents
53
54 [[faq-only-pointer-files]]
55 Why do I end up with small text files in my working tree instead of my files?::
56 Git LFS stores small text files called pointer files in the repository instead
57 of your large files, which it stores elsewhere. These pointer files usually
58 start with the line `version https://git-lfs.github.com/spec/v1`.
59 +
60 Normally, if you've run `git lfs install` at least once for your user account on
61 the system, then Git LFS will be automatically invoked by Git when you check out
62 files or clone a repository and this won't happen. However, if you haven't, or
63 you've explicitly chosen to skip that behaviour by using the `--skip-smudge`
64 option of `git lfs install`, then you may need to use `git lfs pull` to replace
65 the pointer files in your working tree with large files.
66
67 [[faq-working-tree-modified]]
68 Why do I end up with some of my working tree files constantly showing as modified?::
69 This can happen if someone made a commit to a file that's tracked by Git LFS
70 but didn't have Git LFS properly set up on their system. The objects that
71 were checked into the repository are Git objects, not the pointers to Git LFS
72 objects, and when Git checks these files out, it shows them as modified.
73 +
74 There are also several other possible ways to encounter this problem, such as an
75 incomplete migration of your repository. For example, you should not use `git
76 lfs track` to track patterns that are already in your repository without running
77 `git add --renormalize .`, since that can lead to this problem.
78 +
79 Users frequently find that this cannot be changed by doing `git reset --hard` or
80 other techniques because Git then checks the files out and marks them as
81 modified again. The best way to solve this problem is by fixing the files and
82 the committing the change, which you can do with the following on an otherwise
83 clean tree:
84 +
85 [source,shell-session]
86 ----
87 $ git add --renormalize .
88 $ git commit -m "Fix broken LFS files"
89 ----
90 +
91 This requires that every branch you want to fix have this done to it.
92 +
93 To prevent this from reoccurring in the future, make sure that everyone working
94 with large files on a project has run `git lfs install` at least once. The
95 command `git lfs fsck --pointers BASE..HEAD` (with suitable values of `BASE` and
96 `HEAD`) may be used in your CI system to verify that nobody is introducing such
97 problems.
98
99 [[cat-tracking-and-migration]]
100 === Tracking and Migration
101
102 [[faq-track-existing-files]]
103 How do I track files that are already in a repository?::
104 If you want to track files that already exist in a repository, you need to do
105 two things. First, you need to use `git lfs track` (or a manual modification
106 of `.gitattributes`) to mark the files as LFS files. Then, you need to run
107 `git add --renormalize .` and commit the changes to the repository.
108 +
109 If you skip this second step, then you'll end up with files that are marked as
110 LFS files but are stored as Git files, which can lead to files which are always
111 modified, as outlined in the FAQ entry above. Note also that this doesn't
112 change large files in your history. To do that, use `git lfs migrate import
113 --everything` instead, as specified in one of the entries below.
114
115 [[faq-export-to-git]]
116 How do I convert from using Git LFS to a plain Git repository?::
117 If you'd like to stop using Git LFS and switch back to storing your large
118 files in the plain Git format, you can do so with `git lfs migrate export
119 --everything`. Note that you will need to provide an appropriate `--include`
120 option to match all the patterns that you currently have tracked in any ref.
121 +
122 This also rewrites history, so the Git object IDs of many, if not all, of your
123 objects will change.
124
125 [[faq-github-large-files]]
126 I'm using Git LFS, but I still see GitHub's large file error. How do I fix this?::
127 GitHub rejects large files anywhere in the history of your repository, not
128 just in the latest commit. If you're still seeing this message, then you have
129 some large files somewhere in your history, even if in the latest commits
130 you've moved them to Git LFS.
131 +
132 To fix this, you can use `git lfs migrate import --everything` with an
133 appropriate `--include` argument. For example, if you wanted to move your
134 `.jpg` and `.png` files into Git LFS, you can do that with
135 `git lfs migrate import --everything --include="\*.jpg,*.png"`. More complicated
136 patterns are possible: run `git help gitattributes` for more information on
137 valid patterns. Note that if you're specifying directories, using slashes is
138 mandatory: backslashes are not allowed as path separators.
139
140 [[faq-case-sensitivity-patterns]]
141 Does Git LFS pattern matching in `.gitattributes` respect case sensitivity on different operating systems?::
142 Git's `.gitattributes` pattern matching is case-sensitive (consistent with Git's index).
143 On case-insensitive filesystems (default on macOS and Windows), files are often committed
144 with uppercase extensions (e.g., `.PNG`). On case-sensitive filesystems (e.g., Linux CI servers),
145 a pattern like `*.png` won't match `.PNG`, and Git LFS may leave pointer files instead of content.
146 +
147 For repositories shared across platforms, use bracket-glob patterns to match extensions
148 case-insensitively:
149 +
150 [cols="1,1,1,1",options="header"]
151 |===
152 | Original pattern | Recommended pattern | Matches on macOS/Windows | Matches on Linux/CI
153 | `*.png` | `*.[pP][nN][gG]` | Yes | Yes
154 | `*.tga` | `*.[tT][gG][aA]` | Yes | Yes
155 | `*.jpg` | `*.[jJ][pP][gG]` | Yes | Yes
156 | `*.jpeg` | `*.[jJ][pP][eE][gG]` | Yes | Yes
157 |===
158 +
159 Example `.gitattributes` entries:
160 +
161 [source]
162 ----
163 *.[pP][nN][gG] filter=lfs diff=lfs merge=lfs -text
164 *.[tT][gG][aA] filter=lfs diff=lfs merge=lfs -text
165 ----
166 +
167 This uses standard Git pattern syntax with no runtime overhead.
168
169 [[cat-configuration]]
170 === Configuration
171
172 [[faq-proxy]]
173 Can I use a proxy with Git LFS?::
174 Yes, Git LFS supports proxies using the same mechanisms that Git supports,
175 namely the `http_proxy` environment variable and the configuration of
176 `http.proxy` (or `http.*.proxy` for per-URL usage). However, Git LFS only
177 supports proxies which use Basic or no authentication, and it doesn't
178 currently support Digest or Kerberos authentication.
179 +
180 If you're using a proxy, we recommend that you set the full URL in the proxy
181 value, including a scheme. Thus, `http://example.com:3128` is a better choice
182 than `example.com:3128`. If you need a username and password, they must be
183 percent-encoded in the URL, so a username of `foo\bar` with a password of
184 `abc@123+` using the above proxy would be
185 `http://foo%5cbar:abc%40123%[email protected]:3128`.
186 +
187 Note that, just like with Git, proxies must not modify, buffer, tamper with, or
188 change the response to the data in any way, upstream or downstream, and any
189 proxy which does so will break things and is not supported. The Git LFS
190 developers don't recommend any sort of proxy, including any sort of antivirus,
191 firewall, or monitoring software, which performs TLS interception because these
192 are known to cause breakage and in general have been shown to worsen security.
193
194 [[faq-tls-ca]]
195 Can I use a custom set of SSL/TLS certificate authorities with Git LFS?::
196 Yes, Git LFS supports configuring trusted certificate authorities and client
197 certificates for HTTPS, using the same configuration as for Git.
198 +
199 To configure a set of trusted certificate authorities, you can use
200 `http.sslCAPath` to specify a directory of files, each one containing a PKCS#1
201 certificate of a trusted certificate authority. If you'd prefer to use a single
202 file with all trusted certificates, you can use `http.sslCAInfo` to refer to a
203 single file containing PKCS#1 certificates, one following the other.
204 +
205 For example, on Debian, to set this option to provide the default behavior, you
206 could run `git config http.sslCAPath /etc/ssl/certs`. Note that it's also
207 possible to set these configuration options on a per-URL basis, like so: `git
208 config http.https://example.com/.sslCAPath /etc/ssl/certs`.
209 +
210 Note that PKCS#12 files are a Git for Windows extension to Git and are not
211 supported by Git LFS. Additionally, take into account the information about
212 TLS-intercepting proxies above if this configuration is because of a
213 TLS-intercepting proxy.
214
215 [[faq-tls-client-config]]
216 Can I use an SSL/TLS client certificate with Git LFS?::
217 Yes, Git LFS supports configuring client certificates and keys using the same
218 configuration as for Git.
219 +
220 To configure a client certificate, use the `http.sslCert` configuration option
221 pointing to a file containing a PKCS#1 certificate. To configure the
222 corresponding key, use `http.sslKey` with a file containing a PEM-encoded key.
223 If it is encrypted, you will be prompted using the credential helper for the
224 passphrase.
225 +
226 Usually you will want to specify these values on a per-URL basis, such as the
227 following: `git config http.https://example.com/.sslKey
228 /home/user/.certs/mine.key`.
229 +
230 Note that PKCS#8 and PKCS#12 files are not supported by Git LFS.
231
232 [[cat-git-features]]
233 === Working with Git Features
234
235 [[faq-git-diff-on-lfs]]
236 How do I enable git diff to work on LFS files?::
237 You can run `git config diff.lfs.textconv cat`, which will produce normal
238 diffs if your files are text files.
239
240 [[faq-git-diff-on-lfs-by-path]]
241 How do I enable git diff to work on LFS files based on extension or path?::
242 If the above solution is too broad, each entry in the `.gitattributes` file
243 can be customized by creating a custom global converter:
244 +
245 [source,shell-session]
246 ----
247 $ git config --global diff.lfstext.textconv cat
248 ----
249 +
250 Any given `.gitattributes` entry for large text files can be customized to use
251 this global text converter (e.g., patch files), whereas binary formats can
252 continue to use the conventional lfs diff tool, like so:
253 +
254 [source,shell-session]
255 ----
256 $ cat .gitattributes
257 ....
258 *.bin filter=lfs diff=lfs merge=lfs -text
259 *.patch filter=lfs diff=lfstext merge=lfs -text
260 ....
261 ----
262 +
263 Be advised that all developers sharing this repo with such a modified
264 `.gitattributes` file must have similarly configured the `lfstext` text
265 converter, whether globally or on a per repository basis.
266
267 [[faq-archive-subdirectory]]
268 Why are LFS files not included when I archive a subdirectory?::
269 When you run `git archive` with only a subdirectory, such as `git archive
270 HEAD:src`, Git resolves the revision (in this case, `HEAD:src`) to a tree, and
271 only processes items in that tree. Because the `.gitattributes` file is
272 typically only in the root of the repository, Git doesn't even see that file,
273 which controls whether files are considered LFS files, and hence doesn't
274 consider any of the files in the directory as LFS files, and thus doesn't
275 invoke Git LFS at all.
276 +
277 Since Git LFS doesn't even get invoked in this case, there's no way to change
278 how this works. If you just want to include the single subdirectory without
279 stripping the prefix, you can do this: `git archive -o archive.tar.gz
280 --prefix=archive/ HEAD src`. If you do want to strip the subdirectory name
281 (`src`) in this case, one option if you have the libarchive tar (available on Windows
282 and macOS as `tar`, and usually on Linux as `bsdtar`) is to do something like
283 this script:
284 +
285 [source,shell]
286 ----
287 #!/bin/sh
288
289 # With trailing slash.
290 ARCHIVE_PREFIX="archive/"
291 # Without trailing slash.
292 SOURCE_PREFIX="src"
293 # Without directory or file components.
294 REVISION="HEAD"
295
296 temp=$(mktemp -d)
297
298 git archive --prefix="$ARCHIVE_PREFIX" "$REVISION" "$SOURCE_PREFIX" | bsdtar -C "$temp" -xf -
299 bsdtar -s "!^\./!$ARCHIVE_PREFIX!" --format=pax -czf archive.tar.gz -C "$temp/$ARCHIVE_PREFIX$SOURCE_PREFIX" .
300 rm -fr "$temp"
301 ----
302
303 [[cat-non-git-tools]]
304 === Working with Non-Git Tools
305
306 [[faq-jenkins-hooks]]
307 I'm using Jenkins and `git lfs install` fails due to an invalid hook path. What do I do?::
308 Recent versions of Jenkins have set `core.hooksPath` to various values,
309 notably `NUL:` on Windows, with the goal of disabling hooks. This is not a
310 valid path on Windows, nor a valid value for this configuration option, so
311 when `git lfs install` runs and Git LFS attempts to install hooks, the
312 operation fails.
313 +
314 The easiest way to solve this problem is by using the `--skip-repo` option to
315 `git lfs install`, which skips the installation of the hooks. Despite the name,
316 it can be successfully combined with `--local` if you need that option.
317 +
318 Note that this prevents things like `git push` from pushing LFS objects and
319 locked files from being read only, since those are implemented by hooks. If you
320 need that functionality, you should review the Jenkins documentation about how
321 to properly configure the environment in such a situation so that hooks can be
322 used.
323
324 == SEE ALSO
325
326 git-config(1), git-lfs-install(1), gitattributes(5), gitignore(5).
327
328 Part of the git-lfs(1) suite.