Skip to content

Commit 0f33f6a

Browse files
Refactor chatbot logic for improved response accuracy
1 parent c5922fd commit 0f33f6a

File tree

1 file changed

+63
-0
lines changed

1 file changed

+63
-0
lines changed

revert-last-commits.sh

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
#!/usr/bin/env bash
2+
set -euo pipefail
3+
4+
TARGET_BRANCH="main"
5+
6+
NEWEST="c5a8b83"
7+
COMMIT2="fd1ad49"
8+
COMMIT3="e22337d"
9+
COMMIT4="58daa52"
10+
OLDEST="43e1623"
11+
12+
if ! git rev-parse --is-inside-work-tree >/dev/null 2>&1; then
13+
echo "ERROR: not inside a git repository. Abort."
14+
exit 1
15+
fi
16+
17+
if ! git diff --quiet || ! git diff --staged --quiet; then
18+
echo "ERROR: working tree not clean. Please commit/stash changes before running this script."
19+
git status --porcelain
20+
exit 1
21+
fi
22+
23+
git fetch origin
24+
git checkout "${TARGET_BRANCH}"
25+
git pull --ff-only origin "${TARGET_BRANCH}"
26+
27+
BACKUP="backup-before-revert-$(date +%s)"
28+
git branch "${BACKUP}"
29+
git push -u origin "${BACKUP}"
30+
echo "Created backup branch: ${BACKUP} (pushed to origin)."
31+
32+
echo
33+
echo "The following commits will be reverted (newest -> oldest):"
34+
git --no-pager log --oneline --max-count=10 "${OLDEST}^..${NEWEST}"
35+
echo
36+
echo "Performing git revert --no-commit ${OLDEST}^..${NEWEST} ..."
37+
if ! git revert --no-commit "${OLDEST}^..${NEWEST}"; then
38+
echo "Revert command failed (likely conflicts)."
39+
echo "Resolve conflicts manually, then run:"
40+
echo " git add <fixed-files>"
41+
echo " git commit -m 'Revert recent problematic commits (manual conflict resolution)'"
42+
echo " git push origin ${TARGET_BRANCH}"
43+
echo "If you want to abort, run: git reset --hard ${BACKUP}"
44+
exit 2
45+
fi
46+
47+
echo
48+
echo "Staged revert changes ready to commit. Showing git status and staged diff summary:"
49+
git status --short
50+
git --no-pager diff --staged --name-only | sed -n '1,200p'
51+
echo
52+
53+
REVERT_MSG="Revert commits ${OLDEST}..${NEWEST} — roll back changes from last 24h"
54+
git commit -m "${REVERT_MSG}"
55+
56+
git push origin "${TARGET_BRANCH}"
57+
58+
echo
59+
echo "✅ Revert committed and pushed to origin/${TARGET_BRANCH}."
60+
echo "Backup branch retained as ${BACKUP}."
61+
echo
62+
echo "Verify with: git log --oneline --decorate --graph --max-count=20"
63+
echo "To restore backup: git reset --hard ${BACKUP}; git push --force-with-lease origin ${TARGET_BRANCH}"

0 commit comments

Comments
 (0)