36 lines
1007 B
Batchfile
36 lines
1007 B
Batchfile
@echo off
|
|
echo This script will rewrite git history, keeping only the last commit as the new root.
|
|
echo It will also force push to your remote. BACK UP FIRST!
|
|
pause
|
|
|
|
REM Get the current branch name into a variable
|
|
FOR /F "delims=" %%i IN ('git rev-parse --abbrev-ref HEAD') DO set CURRENT_BRANCH=%%i
|
|
|
|
echo Current branch is: %CURRENT_BRANCH%
|
|
pause
|
|
|
|
REM Create a temporary branch from the last commit
|
|
git checkout --orphan temp_branch
|
|
|
|
REM Reset temp_branch to the last commit (keeps files staged)
|
|
git reset --hard HEAD
|
|
|
|
REM Delete old branch
|
|
git branch -D %CURRENT_BRANCH%
|
|
|
|
REM Rename temp_branch to original branch name
|
|
git branch -m %CURRENT_BRANCH%
|
|
|
|
REM Force garbage collection to remove old commits
|
|
git reflog expire --expire=now --all
|
|
git gc --prune=now --aggressive
|
|
|
|
echo Will now force push to remote!
|
|
pause
|
|
|
|
REM Force push to remote origin (replace with your remote if needed)
|
|
git push -f origin %CURRENT_BRANCH%
|
|
|
|
echo Done! The repo now only contains the last commit as the initial release.
|
|
pause
|