-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgit-cleanup.sh
executable file
·84 lines (69 loc) · 2 KB
/
git-cleanup.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
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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
#!/usr/bin/env bash
# https://stackoverflow.com/questions/15617673/git-how-to-delete-all-commits-except-last-one
# rm -rf .git
# git init
# git add .
# git commit -m "Initial commit"
# git branch -M master
# git remote add origin [email protected]:claudiofsr/randy.git
# git push -u --force origin master
# git status
# https://stackoverflow.com/questions/4114095/how-do-i-revert-a-git-repository-to-a-previous-commit
# Using Git — how to go back to a previous commit
# git log --oneline
# Take a note of the ID of the commit you want to revert to
# 4497e26 (HEAD -> main, origin/main, origin/HEAD) worker_threads(4)
# 0b87d60 egui version "0.25"
# b5abeef cargo update
# 87cc1a8 test float format
# 29b0fd0 aligning according to data_col.data_type()
# 90a9de1 Update README.md
# Example, ID: 87cc1a8
# Use git checkout & the ID to go back:
# git checkout ID
# git checkout 87cc1a8
# git checkout 4497e2
# To return from 'detached HEAD' state
# git checkout main (or master or -)
# git log --oneline
# git reset --hard <commitId> && git clean -f
# git push --force
clear
FILE=".git/config"
if [ -f "$FILE" ]
then
printf "$FILE:\n\n"
else
printf "File $FILE is not there, aborting!\n"
exit
fi
config=$(<$FILE)
printf "$config\n\n"
# url = [email protected]:claudiofsr/rust-sped.git
my_url=$(cat .git/config | sed '/url/!d' | sed -r 's/.*=\s*(.*)/\1/')
printf "my_url = '$my_url'\n"
# [branch "master"]
my_branch=$(cat .git/config | sed '/branch/!d' | sed -r 's/.*branch\s*"(.*)".*/\1/')
printf "my_branch = '$my_branch'\n"
# Define your function here
new_git () {
rm -rf .git
git init
# edit .gitignore
git add .
git commit -m "Initial commit"
git branch -M $my_branch
git remote add origin $my_url
git push -u --force origin $my_branch
}
while true; do
printf "\n"
printf "\t Delete .git directory\n"
printf "\t Continue? (Y/N):"
read yn
case $yn in
[Yy]* ) new_git; break;;
[Nn]* ) exit;;
* ) printf "\n\t Please answer Y or N.\n";;
esac
done