#!/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:00+00:00' export GIT_COMMITTER_DATE='2026-10-25T12:00:00+00:00' test "$(git version)" = 'git version 2.56.0' start_case() { mkdir "$1" cd "$1" git init -q --template= --initial-branch=main --object-format=sha1 git config commit.gpgsign false git config core.autocrlf false printf 'base\n' > note.txt git add note.txt git commit -qm 'Base note' printf 'base\nsecond line\n' > note.txt git commit -qam 'Add second line' } start_case soft-example before=$(git rev-parse HEAD) git reset --soft HEAD~1 test "$(git rev-list --count HEAD)" = 1 test "$(git status --porcelain=v1)" = 'M note.txt' test "$(git show :note.txt)" = "$(cat note.txt)" printf 'Soft reset: one commit; second line remains staged\n' git status --short git log -1 --format='%h %s' git reset --soft "$before" test -z "$(git status --porcelain=v1)" printf 'Saved commit restored before any further edits\n' cd .. start_case mixed-example git reset --mixed -q HEAD~1 test "$(git rev-list --count HEAD)" = 1 test "$(git status --porcelain=v1)" = ' M note.txt' test "$(git show :note.txt)" = base test "$(cat note.txt)" = "$(printf 'base\nsecond line')" printf 'Mixed reset: one commit; second line remains unstaged\n' git status --short cd .. start_case amend-example old=$(git rev-parse HEAD) printf 'extra note\n' > extra.txt git add extra.txt git commit --amend -qm 'Add second line and extra note' test "$(git rev-list --count HEAD)" = 2 test "$(git rev-parse HEAD)" != "$old" test "$(git show HEAD:extra.txt)" = 'extra note' test -z "$(git status --porcelain=v1)" printf 'Amend: replacement commit includes the staged extra file\n' git log -1 --format='%h %s'