@@ -88,7 +88,7 @@ git filter-repo \
88
88
Replace "stuff" in any commit message with "task".
89
89
90
90
```
91
- git- filter-repo --message-callback 'return message.replace(b"stuff", b"task")'
91
+ git filter-repo --message-callback 'return message.replace(b"stuff", b"task")'
92
92
```
93
93
94
94
## Only keep files from two branches
@@ -245,12 +245,21 @@ git filter-repo --refs main~5..main --commit-callback '
245
245
246
246
First, run fsck to get a list of the corrupt objects, e.g.:
247
247
```
248
- $ git fsck
248
+ $ git fsck --full
249
249
error in commit 166f57b3fbe31257100361ecaf735f305b533b21: missingSpaceBeforeDate: invalid author/committer line - missing space before date
250
+ error in tree c15680eae81cc8539af7e7de766a8a7c13bd27df: duplicateEntries: contains duplicate file entries
250
251
Checking object directories: 100% (256/256), done.
251
252
```
252
253
253
- Then print out that object literally to a temporary file:
254
+ Odds are you'll only see one type of corruption, but if you see
255
+ multiple, you can either do multiple filterings, or create replacement
256
+ objects for all the corrupt objects (both commits and trees), and then
257
+ do the filtering. Since the method for handling corrupt commits and
258
+ corrupt tress is slightly different, I'll give examples below for each.
259
+
260
+ ### Handling repository corruption -- commit objects
261
+
262
+ Print out the corrupt object literally to a temporary file:
254
263
```
255
264
$ git cat-file -p 166f57b3fbe31257100361ecaf735f305b533b21 >tmp
256
265
```
@@ -266,7 +275,8 @@ Initial
266
275
```
267
276
268
277
Edit that file to fix the error (in this case, the missing space
269
- between author email and author date):
278
+ between author email and author date). In this case, it would look
279
+ like this after editing:
270
280
271
281
```
272
282
tree e1d871155fce791680ec899fe7869067f2b4ffd2
276
286
Initial
277
287
```
278
288
279
- Save the updated file, then use ` git- replace ` to make a replace reference
289
+ Save the updated file, then use ` git replace ` to make a replace reference
280
290
for it.
281
291
```
282
292
$ git replace -f 166f57b3fbe31257100361ecaf735f305b533b21 $(git hash-object -t commit -w tmp)
@@ -294,6 +304,62 @@ Note that if you have multiple corrupt objects, you only need to run
294
304
filter-repo once; that is, so long as you create all the replacements
295
305
before you run filter-repo.
296
306
307
+ ### Handling repository corruption -- tree objects
308
+
309
+ <!-- GitHub customer example -->
310
+
311
+ Print out the corrupt object literally to a temporary file:
312
+ ```
313
+ $ git cat-file -p c15680eae81cc8539af7e7de766a8a7c13bd27df >tmp
314
+ ```
315
+
316
+ Taking a look at the file would show, for example:
317
+ ```
318
+ $ cat tmp
319
+ 100644 blob cd5ded43e86f80bfd384702e3f4cc7ce42de49f9 .gitignore
320
+ 100644 blob 226febfcc91ec2c166a5a06834fb47c3553ec469 README.md
321
+ 100644 blob e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 src
322
+ 040000 tree df2b8fc99e1c1d4dbc0a854d9f72157f1d6ea078 src
323
+ 040000 tree 99d732476808176bb9d73bcbfe2505e43d65cb4f t
324
+ ```
325
+
326
+ Edit that file to fix the error (in this case, removing either the ` src `
327
+ file (blob) or the ` src ` directory (tree)). In this case, it might look
328
+ like this after editing:
329
+
330
+ ```
331
+ 100644 blob cd5ded43e86f80bfd384702e3f4cc7ce42de49f9 .gitignore
332
+ 100644 blob 226febfcc91ec2c166a5a06834fb47c3553ec469 README.md
333
+ 040000 tree df2b8fc99e1c1d4dbc0a854d9f72157f1d6ea078 src
334
+ 040000 tree 99d732476808176bb9d73bcbfe2505e43d65cb4f t
335
+ ```
336
+
337
+ Save the updated file, then use ` git mktree ` to turn it into an actual
338
+ tree object:
339
+ ```
340
+ $ git mktree <tmp
341
+ ace04f50a5d13b43e94c12802d3d8a6c66a35b1d
342
+ ```
343
+
344
+ Now use the output of that command to create a replacement object for
345
+ the original corrupt object:
346
+ ```
347
+ git replace -f c15680eae81cc8539af7e7de766a8a7c13bd27df ace04f50a5d13b43e94c12802d3d8a6c66a35b1d
348
+ ```
349
+
350
+ Then remove the temporary file ` tmp ` and run ` filter-repo ` to consume
351
+ the replace reference and make it permanent:
352
+
353
+ ```
354
+ $ rm tmp
355
+ $ git filter-repo --proceed
356
+ ```
357
+
358
+ As mentioned with corrupt commit objects, if you have multiple corrupt
359
+ objects, as long as you create all the replacements for those objects
360
+ first, you only need to run filter-repo once.
361
+
362
+
297
363
## Removing all files with a backslash in them
298
364
299
365
<!-- https://github.com/newren/git-filter-repo/issues/427 -->
0 commit comments