-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path08_revert-to-commit.bat
More file actions
66 lines (57 loc) · 1.37 KB
/
08_revert-to-commit.bat
File metadata and controls
66 lines (57 loc) · 1.37 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
@echo off
echo ====================================
echo REVERT TO A SPECIFIC COMMIT
echo ====================================
echo.
echo [1/4] Displaying the last 20 commits...
echo.
git log --oneline -20
echo.
echo ====================================
echo.
set /p commit_hash="Enter the commit hash (the first 7 characters): "
if "%commit_hash%"=="" (
echo ERROR: Hash cannot be empty!
pause
exit /b 1
)
echo.
echo WARNING: This action will:
echo 1. Delete all uncommitted changes
echo 2. Revert to commit: %commit_hash%
echo 3. Commits AFTER this point will be lost locally
echo.
set /p confirm="Are you sure you want to continue? (y/n): "
if /i not "%confirm%"=="y" (
echo.
echo Operation cancelled.
pause
exit /b 0
)
echo.
echo [2/4] Resetting to commit %commit_hash%...
git reset --hard %commit_hash%
if %errorlevel% neq 0 (
echo ERROR: Unable to revert to the commit!
pause
exit /b 1
)
echo.
echo [3/4] Cleaning untracked files...
git clean -fd
echo.
echo [4/4] Done!
echo ====================================
echo REVERT TO COMMIT SUCCESSFUL!
echo ====================================
echo.
echo You are now on commit: %commit_hash%
echo.
echo IMPORTANT:
echo - Your local files have been restored
echo - To synchronize with GitHub:
echo git push origin main --force
echo.
echo WARNING: Use --force ONLY if you are sure!
echo.
pause