-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathclean.sh
31 lines (22 loc) · 794 Bytes
/
clean.sh
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
#!/bin/bash
# WARNING: This script will completely erase the commit history of the specified branch.
# Use with extreme caution and ensure you have a backup of your repository.
# Check if a branch name is provided
if [ $# -eq 0 ]; then
echo "No branch name provided. Using 'master' as default."
branch="master"
else
branch=$1
fi
# Step 1: Create a new orphan branch (new_branch is a temporary name)
git checkout --orphan new_branch
# Step 2: Add all files and commit
git add -A
git commit -m "Initial commit"
# Step 3: Delete the old branch
git branch -D $branch
# Step 4: Rename the orphan branch to the original branch name
git branch -m $branch
# Step 5: Force push to overwrite the remote branch
git push -f origin $branch
echo "Repository history has been rewritten!"