Skip to content

Commit 0ee22eb

Browse files
committed
examples-from-user-filed-issues.md: cover corrupt trees too
Handling corrupt trees is similar to handling corrupt commits, but the editing is slightly different, so just add an example so that we cover both types of corruption. Signed-off-by: Elijah Newren <[email protected]>
1 parent 9e20eef commit 0ee22eb

File tree

1 file changed

+71
-5
lines changed

1 file changed

+71
-5
lines changed

Documentation/examples-from-user-filed-issues.md

+71-5
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ git filter-repo \
8888
Replace "stuff" in any commit message with "task".
8989

9090
```
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")'
9292
```
9393

9494
## Only keep files from two branches
@@ -245,12 +245,21 @@ git filter-repo --refs main~5..main --commit-callback '
245245

246246
First, run fsck to get a list of the corrupt objects, e.g.:
247247
```
248-
$ git fsck
248+
$ git fsck --full
249249
error in commit 166f57b3fbe31257100361ecaf735f305b533b21: missingSpaceBeforeDate: invalid author/committer line - missing space before date
250+
error in tree c15680eae81cc8539af7e7de766a8a7c13bd27df: duplicateEntries: contains duplicate file entries
250251
Checking object directories: 100% (256/256), done.
251252
```
252253

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:
254263
```
255264
$ git cat-file -p 166f57b3fbe31257100361ecaf735f305b533b21 >tmp
256265
```
@@ -266,7 +275,8 @@ Initial
266275
```
267276

268277
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:
270280

271281
```
272282
tree e1d871155fce791680ec899fe7869067f2b4ffd2
@@ -276,7 +286,7 @@ committer My Name <[email protected]> 1673287380 -0800
276286
Initial
277287
```
278288

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
280290
for it.
281291
```
282292
$ 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
294304
filter-repo once; that is, so long as you create all the replacements
295305
before you run filter-repo.
296306

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+
297363
## Removing all files with a backslash in them
298364

299365
<!-- https://github.com/newren/git-filter-repo/issues/427 -->

0 commit comments

Comments
 (0)