mirror of
https://github.com/git/git.git
synced 2024-11-18 15:03:53 +01:00
566842f62b
Prior to 1.5.0 the git-lost-found utility was useful to locate commits that were not referenced by any ref. These were often amends, or resets, or tips of branches that had been deleted. Being able to locate a 'lost' commit and recover it by creating a new branch was a useful feature in those days. Unfortunately 1.5.0 added the reflogs to the reachability analysis performed by git-fsck, which means that most commits users would consider to be lost are still reachable through a reflog. So most (or all!) commits are reachable, and nothing gets output from git-lost-found. Now git-fsck can be told to ignore reflogs during its reachability analysis, making git-lost-found useful again to locate commits that are no longer referenced by a ref itself, but may still be referenced by a reflog. Signed-off-by: Shawn O. Pearce <spearce@spearce.org> Signed-off-by: Junio C Hamano <junkio@cox.net>
31 lines
473 B
Bash
Executable File
31 lines
473 B
Bash
Executable File
#!/bin/sh
|
|
|
|
USAGE=''
|
|
SUBDIRECTORY_OK='Yes'
|
|
. git-sh-setup
|
|
|
|
if [ "$#" != "0" ]
|
|
then
|
|
usage
|
|
fi
|
|
|
|
laf="$GIT_DIR/lost-found"
|
|
rm -fr "$laf" && mkdir -p "$laf/commit" "$laf/other" || exit
|
|
|
|
git fsck --full --no-reflogs |
|
|
while read dangling type sha1
|
|
do
|
|
case "$dangling" in
|
|
dangling)
|
|
if git-rev-parse --verify "$sha1^0" >/dev/null 2>/dev/null
|
|
then
|
|
dir="$laf/commit"
|
|
git-show-branch "$sha1"
|
|
else
|
|
dir="$laf/other"
|
|
fi
|
|
echo "$sha1" >"$dir/$sha1"
|
|
;;
|
|
esac
|
|
done
|