#!/bin/bash # POZOR: SKRIPT JE SKORAJ V CELOTI NAPISALA UMETNA INTELIGENCA!!! set -euo pipefail repo=$1 # git-dir date=$2 # 2026-05-01 CUTOFF_TS=$(date -d "$date" +%s) best_sha="" best_ts=0 git --git-dir $repo cat-file --batch-all-objects --batch-check='%(objectname) %(objecttype)' | awk '$2=="commit"{print $1}' | while read -r sha; do ts=$(git --git-dir $repo show -s --format=%ct "$sha" 2>/dev/null || true) if [[ -n "$ts" && "$ts" -lt "$CUTOFF_TS" ]]; then echo "$ts $sha" fi done | sort -n | tail -1 | { read -r best_ts best_sha if [[ -z "${best_sha:-}" ]]; then echo "No commit found before $date" >&2 exit 1 fi git --git-dir $repo branch -f restored "$best_sha" echo "Created branch 'restored' at:" git --git-dir $repo show -s --format='%H %ci %s' restored }