#!/bin/sh # SPDX-License-Identifier: MIT set -eu export TZ=UTC LC_ALL=C export GIT_CONFIG_NOSYSTEM=1 GIT_CONFIG_GLOBAL=/dev/null export GIT_AUTHOR_NAME='Example Author' export GIT_AUTHOR_EMAIL='author@example.invalid' export GIT_COMMITTER_NAME='Example Author' export GIT_COMMITTER_EMAIL='author@example.invalid' export GIT_AUTHOR_DATE='2026-10-25T12:00:00Z' export GIT_COMMITTER_DATE='2026-10-25T12:00:00Z' test "$(git --version)" = 'git version 2.56.0' mkdir recovery-example cd recovery-example git -c init.templateDir= init -q -b main printf 'base\n' > note.txt git add note.txt git commit -qm 'Base' git switch -qc topic printf 'unique topic work\n' > note.txt git commit -qam 'Unique topic work' original_tip=$(git rev-parse HEAD) git switch -q main # This deletion is only for the newly created fictional repository. git branch -D topic > deletion.txt cat deletion.txt git reflog show HEAD --format='%h %gs' candidate=$(git rev-parse 'HEAD@{1}') test "$candidate" = "$original_tip" test "$candidate" != "$(git rev-parse HEAD)" git show --format=fuller --stat "$candidate" test "$(git show "$candidate":note.txt)" = 'unique topic work' git branch recovered "$candidate" test "$(git rev-parse recovered)" = "$original_tip" test "$(git branch --show-current)" = main printf 'recovery: original tip named; main remains checked out\n'