git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH v2 08/11] contrib: remove "git-resurrect.sh"

From
Patrick Steinhardt <ps@pks.im>
Date
May 9, 2025, 09:17 UTC
Message-ID
<20250509-pks-contrib-spring-cleanup-v2-8-14e20d95ec68@pks.im>
In-Reply-To
<20250509-pks-contrib-spring-cleanup-v2-0-14e20d95ec68@pks.im>

The "git-resurrect.sh" script can be used to find traces of a branch tip in the reflog and resurrect that branch. Despite a couple of global cleanups, the script hasn't seen any activity since it was introduced in e1ff064e1bf (contrib git-resurrect: find traces of a branch name and resurrect it, 2009-02-04).

Furthermore, the tool does not work with the "reftable" backend at all as it directly reads ".git/logs/HEAD". As reflogs are stored as part of the individual tables though that file wouldn't exist in a "reftable"- enabled repository.

Last but not least, the tool doesn't even work unless it is explicitly invoked via `git resurrect` as it sources "git-sh-setup". As none of our build systems know to install this script, users thus have to go out of their way to really make it work, which is highly unlikely.

Another source that indicates that this tool can be removed is a question for how to restore deleted branches on StackOverflow [1]. The top-voted answer uses git-reflog(1) directly and has received more than 3000 votes to date. While "git-resurrect.sh" is also mentioned, it only got 16 upvotes, and comments mention the above caveat that users have to do some manual setup to make it work.

It's thus rather clear that the tool doesn't have a lot or even any users. Remove it.

[1]: https://stackoverflow.com/questions/3640764/can-i-recover-a-branch-after-its-deletion-in-git
Signed-off-by: Patrick Steinhardt <ps@pks.im>
---
 contrib/git-resurrect.sh | 181 -----------------------------------------------
 1 file changed, 181 deletions(-)
diff --git a/contrib/git-resurrect.sh b/contrib/git-resurrect.sh
deleted file mode 100755
index d843df3afd0..00000000000
--- a/contrib/git-resurrect.sh
+++ /dev/null
@@ -1,181 +0,0 @@
-#!/bin/sh
-
-USAGE="[-a] [-r] [-m] [-t] [-n] [-b <newname>] <name>"
-LONG_USAGE="git-resurrect attempts to find traces of a branch tip
-called <name>, and tries to resurrect it.  Currently, the reflog is
-searched for checkout messages, and with -r also merge messages.  With
--m and -t, the history of all refs is scanned for Merge <name> into
-other/Merge <other> into <name> (respectively) commit subjects, which
-is rather slow but allows you to resurrect other people's topic
-branches."
-
-OPTIONS_KEEPDASHDASH=
-OPTIONS_STUCKLONG=
-OPTIONS_SPEC="\
-git resurrect $USAGE
---
-b,branch=            save branch as <newname> instead of <name>
-a,all                same as -l -r -m -t
-k,keep-going         full rev-list scan (instead of first match)
-l,reflog             scan reflog for checkouts (enabled by default)
-r,reflog-merges      scan for merges recorded in reflog
-m,merges             scan for merges into other branches (slow)
-t,merge-targets      scan for merges of other branches into <name>
-n,dry-run            don't recreate the branch"
-
-. git-sh-setup
-
-search_reflog () {
-	sed -ne 's~^\([^ ]*\) .*	checkout: moving from '"$1"' .*~\1~p' \
-		< "$GIT_DIR"/logs/HEAD
-}
-
-search_reflog_merges () {
-	git rev-parse $(
-		sed -ne 's~^[^ ]* \([^ ]*\) .*	merge '"$1"':.*~\1^2~p' \
-			< "$GIT_DIR"/logs/HEAD
-	)
-}
-
-oid_pattern=$(git hash-object --stdin </dev/null | sed -e 's/./[0-9a-f]/g')
-
-search_merges () {
-	git rev-list --all --grep="Merge branch '$1'" \
-		--pretty=tformat:"%P %s" |
-	sed -ne "/^$oid_pattern \($oid_pattern\) Merge .*/ {s//\1/p;$early_exit}"
-}
-
-search_merge_targets () {
-	git rev-list --all --grep="Merge branch '[^']*' into $branch\$" \
-		--pretty=tformat:"%H %s" --all |
-	sed -ne "/^\($oid_pattern\) Merge .*/ {s//\1/p;$early_exit} "
-}
-
-dry_run=
-early_exit=q
-scan_reflog=t
-scan_reflog_merges=
-scan_merges=
-scan_merge_targets=
-new_name=
-
-while test "$#" != 0; do
-	case "$1" in
-	    -b|--branch)
-		shift
-		new_name="$1"
-		;;
-	    -n|--dry-run)
-		dry_run=t
-		;;
-	    --no-dry-run)
-		dry_run=
-		;;
-	    -k|--keep-going)
-		early_exit=
-		;;
-	    --no-keep-going)
-		early_exit=q
-		;;
-	    -m|--merges)
-		scan_merges=t
-		;;
-	    --no-merges)
-		scan_merges=
-		;;
-	    -l|--reflog)
-		scan_reflog=t
-		;;
-	    --no-reflog)
-		scan_reflog=
-		;;
-	    -r|--reflog_merges)
-		scan_reflog_merges=t
-		;;
-	    --no-reflog_merges)
-		scan_reflog_merges=
-		;;
-	    -t|--merge-targets)
-		scan_merge_targets=t
-		;;
-	    --no-merge-targets)
-		scan_merge_targets=
-		;;
-	    -a|--all)
-		scan_reflog=t
-		scan_reflog_merges=t
-		scan_merges=t
-		scan_merge_targets=t
-		;;
-	    --)
-		shift
-		break
-		;;
-	    *)
-		usage
-		;;
-	esac
-	shift
-done
-
-test "$#" = 1 || usage
-
-all_strategies="$scan_reflog$scan_reflog_merges$scan_merges$scan_merge_targets"
-if test -z "$all_strategies"; then
-	die "must enable at least one of -lrmt"
-fi
-
-branch="$1"
-test -z "$new_name" && new_name="$branch"
-
-if test ! -z "$scan_reflog"; then
-	if test -r "$GIT_DIR"/logs/HEAD; then
-		candidates="$(search_reflog $branch)"
-	else
-		die 'reflog scanning requested, but' \
-			'$GIT_DIR/logs/HEAD not readable'
-	fi
-fi
-if test ! -z "$scan_reflog_merges"; then
-	if test -r "$GIT_DIR"/logs/HEAD; then
-		candidates="$candidates $(search_reflog_merges $branch)"
-	else
-		die 'reflog scanning requested, but' \
-			'$GIT_DIR/logs/HEAD not readable'
-	fi
-fi
-if test ! -z "$scan_merges"; then
-	candidates="$candidates $(search_merges $branch)"
-fi
-if test ! -z "$scan_merge_targets"; then
-	candidates="$candidates $(search_merge_targets $branch)"
-fi
-
-candidates="$(git rev-parse $candidates | sort -u)"
-
-if test -z "$candidates"; then
-	hint=
-	test "z$all_strategies" != "ztttt" \
-		&& hint=" (maybe try again with -a)"
-	die "no candidates for $branch found$hint"
-fi
-
-echo "** Candidates for $branch **"
-for cmt in $candidates; do
-	git --no-pager log --pretty=tformat:"%ct:%h [%cr] %s" --abbrev-commit -1 $cmt
-done \
-| sort -n | cut -d: -f2-
-
-newest="$(git rev-list -1 $candidates)"
-if test ! -z "$dry_run"; then
-	printf "** Most recent: "
-	git --no-pager log -1 --pretty=tformat:"%h %s" $newest
-elif ! git rev-parse --verify --quiet $new_name >/dev/null; then
-	printf "** Restoring $new_name to "
-	git --no-pager log -1 --pretty=tformat:"%h %s" $newest
-	git branch $new_name $newest
-else
-	printf "Most recent: "
-	git --no-pager log -1 --pretty=tformat:"%h %s" $newest
-	echo "** $new_name already exists, doing nothing"
-fi
-- 
2.49.0.1077.gc0e912fd4c.dirty
Previous: Patrick SteinhardtNext: Patrick Steinhardt
Message 41 of 62 in “Spring cleanup of "contrib/"”
  1. 00/10 Spring cleanup of "contrib/"Patrick Steinhardt, May 6, 2025
  2. 02/10 contrib: remove "examples" directoryPatrick Steinhardt, May 6, 2025
  3. 01/10 contrib: remove "remotes2config.sh"Patrick Steinhardt, May 6, 2025
  4. Junio C HamanoMay 6, 2025
  5. Patrick SteinhardtMay 7, 2025
  6. Junio C HamanoMay 7, 2025
  7. 03/10 contrib: remove remote-helper stubsPatrick Steinhardt, May 6, 2025
  8. 04/10 contrib: remove "thunderbird-patch-inline"Patrick Steinhardt, May 6, 2025
  9. 05/10 contrib: remove "hooks" directoryPatrick Steinhardt, May 6, 2025
  10. 06/10 contrib: remove "mw-to-git"Patrick Steinhardt, May 6, 2025
  11. Junio C HamanoMay 6, 2025
  12. Matthieu MoyMay 7, 2025
  13. 08/10 contrib: remove "git-resurrect.sh"Patrick Steinhardt, May 6, 2025
  14. Junio C HamanoMay 6, 2025
  15. Patrick SteinhardtMay 7, 2025
  16. Junio C HamanoMay 7, 2025
  17. Kristoffer HaugsbakkMay 7, 2025
  18. 09/10 contrib: remove "emacs" directoryPatrick Steinhardt, May 6, 2025
  19. Junio C HamanoMay 6, 2025
  20. 07/10 contrib: remove "persistent-https" remote helperPatrick Steinhardt, May 6, 2025
  21. Junio C HamanoMay 6, 2025
  22. 10/10 contrib: remove "git-new-workdir"Patrick Steinhardt, May 6, 2025
  23. Junio C HamanoMay 6, 2025
  24. Patrick SteinhardtMay 7, 2025
  25. Junio C HamanoMay 7, 2025
  26. Patrick SteinhardtMay 9, 2025
  27. Junio C HamanoMay 6, 2025
  28. Eric SunshineMay 6, 2025
  29. Todd ZullingerMay 7, 2025
  30. Eric SunshineMay 7, 2025
  31. Patrick SteinhardtMay 7, 2025
  32. D. Ben KnobleMay 10, 2025
  33. Phillip WoodMay 12, 2025
  34. 00/11 Spring cleanup of "contrib/"Patrick Steinhardt, May 9, 2025
  35. 01/11 contrib: remove "remotes2config.sh"Patrick Steinhardt, May 9, 2025
  36. 02/11 contrib: remove "examples" directoryPatrick Steinhardt, May 9, 2025
  37. 03/11 contrib: remove remote-helper stubsPatrick Steinhardt, May 9, 2025
  38. 04/11 contrib: remove "thunderbird-patch-inline"Patrick Steinhardt, May 9, 2025
  39. 05/11 contrib: remove "hooks" directoryPatrick Steinhardt, May 9, 2025
  40. 06/11 contrib: remove "mw-to-git"Patrick Steinhardt, May 9, 2025
  41. 08/11 contrib: remove "git-resurrect.sh"Patrick Steinhardt, May 9, 2025
  42. 07/11 contrib: remove "persistent-https" remote helperPatrick Steinhardt, May 9, 2025
  43. 09/11 contrib: remove "emacs" directoryPatrick Steinhardt, May 9, 2025
  44. 10/11 contrib: remove "git-new-workdir"Patrick Steinhardt, May 9, 2025
  45. 11/11 contrib: remove "stats" directoryPatrick Steinhardt, May 9, 2025
  46. Elijah NewrenMay 9, 2025
  47. Elijah NewrenMay 9, 2025
  48. Junio C HamanoMay 10, 2025
  49. Patrick SteinhardtMay 12, 2025
  50. Collin FunkMay 12, 2025
  51. Phillip WoodMay 12, 2025
  52. Patrick SteinhardtMay 12, 2025
  53. Junio C HamanoMay 12, 2025
  54. Phillip WoodMay 14, 2025
  55. contrib: update thunderbird-patch-inlinePhillip Wood, May 16, 2025
  56. Kristoffer HaugsbakkMay 16, 2025
  57. Patrick SteinhardtMay 19, 2025
  58. Collin FunkMay 19, 2025
  59. Phillip WoodMay 19, 2025
  60. Junio C HamanoJun 3, 2025
  61. Junio C HamanoMay 19, 2025
  62. Peter KreftingMay 10, 2025

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.