-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgit_helper
More file actions
executable file
·66 lines (56 loc) · 1.29 KB
/
git_helper
File metadata and controls
executable file
·66 lines (56 loc) · 1.29 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
#!/bin/bash
# Color codes
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
NC='\033[0m' # No Color
# A helper script to perform various git operations
function clean_repo() {
echo "git clean -df"
echo -e "${YELLOW}Cleaning the repo by removing untracked files...${NC}"
git clean -df
}
function discard_changes() {
echo "git restore ."
echo -e "${YELLOW}Discarding all local changes...${NC}"
git restore .
}
function remove_last_commit() {
echo "git reset HEAD~1"
echo -e "${YELLOW}Removing the last commit...${NC}"
git reset HEAD~1
}
function reset_to_commit() {
if [ -z "$1" ]; then
echo -e "${RED}Error: Please provide a commit hash.${NC}"
exit 1
fi
echo 'git reset --hard "$1"'
echo -e "${YELLOW}Resetting to commit: ${GREEN}$1${NC}"
git reset --hard "$1"
}
function usage() {
echo -e "${GREEN}Usage: $0 {clean_repo|discard_changes|remove_last_commit|reset_to_commit <commit_hash>}${NC}"
exit 1
}
if [ $# -lt 1 ]; then
usage
fi
case "$1" in
clean_repo)
clean_repo
;;
discard_changes)
discard_changes
;;
remove_last_commit)
remove_last_commit
;;
reset_to_commit)
shift
reset_to_commit "$@"
;;
*)
usage
;;
esac