@matheusbsbs / matheus-bagliano / commits / 04e7ca1a1b
Fork 0

git-lost+found

This command helps you resurrect accidentally lost tags and commits. Signed-off-by: Junio C Hamano <junkio@cox.net>

Junio C Hamano committed Nov 7, 2005 at 15:15 UTC 04e7ca1a1bd05e733236734bd7078b4cde1f7ce5
4 files changed +106 -1
Documentation/git-lost+found.txt new
+78
@@ -0,0 +1,78 @@
1 +git-lost+found(1)
2 +=================
3 +
4 +NAME
5 +----
6 +git-lost+found - Recover lost refs that luckily have not yet been pruned.
7 +
8 +SYNOPSIS
9 +--------
10 +'git-lost+found'
11 +
12 +DESCRIPTION
13 +-----------
14 +Finds dangling commits and tags from the object database, and
15 +creates refs to them in .git/lost+found/ directory. Commits and
16 +tags that dereference to commits go to .git/lost+found/commit
17 +and others are stored in .git/lost+found/other directory.
18 +
19 +
20 +OUTPUT
21 +------
22 +One line description from the commit and tag found along with
23 +their object name are printed on the standard output.
24 +
25 +
26 +EXAMPLE
27 +-------
28 +
29 +Suppose you run 'git tag -f' and mistyped the tag to overwrite.
30 +The ref to your tag is overwritten, but until you run 'git
31 +prune', it is still there.
32 +
33 +------------
34 +$ git lost+found
35 +[1ef2b196d909eed523d4f3c9bf54b78cdd6843c6] GIT 0.99.9c
36 +...
37 +------------
38 +
39 +Also you can use gitk to browse how they relate to each other
40 +and existing (probably old) tags.
41 +
42 +------------
43 +$ gitk $(cd .git/lost+found/commit && echo ??*)
44 +------------
45 +
46 +After making sure that it is the object you are looking for, you
47 +can reconnect it to your regular .git/refs hierarchy.
48 +
49 +------------
50 +$ git cat-file -t 1ef2b196
51 +tag
52 +$ git cat-file tag 1ef2b196
53 +object fa41bbce8e38c67a218415de6cfa510c7e50032a
54 +type commit
55 +tag v0.99.9c
56 +tagger Junio C Hamano <junkio@cox.net> 1131059594 -0800
57 +
58 +GIT 0.99.9c
59 +
60 +This contains the following changes from the "master" branch, since
61 +...
62 +$ git update-ref refs/tags/not-lost-anymore 1ef2b196
63 +$ git rev-parse not-lost-anymore
64 +1ef2b196d909eed523d4f3c9bf54b78cdd6843c6
65 +------------
66 +
67 +Author
68 +------
69 +Written by Junio C Hamano <junkio@cox.net>
70 +
71 +Documentation
72 +--------------
73 +Documentation by Junio C Hamano and the git-list <git@vger.kernel.org>.
74 +
75 +
76 +GIT
77 +---
78 +Part of the gitlink:git[7] suite
Documentation/git.txt
+3
@@ -309,6 +309,9 @@ gitlink:git-convert-objects[1]::
309 gitlink:git-cvsimport[1]::
310 Salvage your data out of another SCM people love to hate.
311
312 +gitlink:git-lost+found[1]::
313 + Recover lost refs that luckily have not yet been pruned.
314 +
315 gitlink:git-merge-one-file[1]::
316 The standard helper program to use with "git-merge-index"
317
Makefile
+2 -1
@@ -89,7 +89,8 @@ SCRIPT_SH = \
89 git-tag.sh git-verify-tag.sh git-whatchanged.sh git.sh \
90 git-applymbox.sh git-applypatch.sh git-am.sh \
91 git-merge.sh git-merge-stupid.sh git-merge-octopus.sh \
92 - git-merge-resolve.sh git-merge-ours.sh git-grep.sh
92 + git-merge-resolve.sh git-merge-ours.sh git-grep.sh \
93 + git-lost+found.sh
94
95 SCRIPT_PERL = \
96 git-archimport.perl git-cvsimport.perl git-relink.perl \
git-lost+found.sh new
+23
@@ -0,0 +1,23 @@
1 +#!/bin/sh
2 +
3 +. git-sh-setup || die "Not a git archive."
4 +
5 +laf="$GIT_DIR/lost+found"
6 +rm -fr "$laf" && mkdir -p "$laf/commit" "$laf/other" || exit
7 +
8 +git fsck-objects |
9 +while read dangling type sha1
10 +do
11 + case "$dangling" in
12 + dangling)
13 + if git-rev-parse --verify "$sha1^0" >/dev/null 2>/dev/null
14 + then
15 + dir="$laf/commit"
16 + git-show-branch "$sha1"
17 + else
18 + dir="$laf/other"
19 + fi
20 + echo "$sha1" >"$dir/$sha1"
21 + ;;
22 + esac
23 +done