TET-CRAFT / gitoops.sh
six1free's picture
Fixed app.py?
fb3f189
ο»Ώ#!/bin/bash
# Git Oops Toolkit - Fix common git mistakes
# Colors
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
NC='\033[0m' # No Color
# Check if in a git repo
check_git_repo() {
if ! git rev-parse --git-dir > /dev/null 2>&1; then
echo -e "${RED}Error: Not in a git repository!${NC}"
exit 1
fi
}
# Function 1: Undo last commit (keep changes)
git_oops() {
echo -e "${YELLOW}=== Undo Last Commit ===${NC}"
echo "This will undo your last commit but keep all changes staged."
echo ""
echo -e "${BLUE}Current commit:${NC}"
git log -1 --oneline
echo ""
read -p "Undo this commit? (y/n): " -n 1 -r
echo
if [[ $REPLY =~ ^[Yy]$ ]]; then
git reset --soft HEAD~1
echo -e "${GREEN}βœ“ Commit undone! Your changes are still staged.${NC}"
else
echo "Cancelled."
fi
}
# Function 2: Unstage a specific file
git_oops_file() {
echo -e "${YELLOW}=== Unstage File ===${NC}"
echo ""
echo -e "${BLUE}Currently staged files:${NC}"
git diff --cached --name-only
echo ""
read -p "Enter filename to unstage: " filename
if [ -z "$filename" ]; then
echo "No filename provided. Cancelled."
return
fi
git reset HEAD "$filename" 2>/dev/null
if [ $? -eq 0 ]; then
echo -e "${GREEN}βœ“ Unstaged: $filename${NC}"
else
echo -e "${RED}Error: Could not unstage $filename${NC}"
fi
}
# Function 3: Hard reset (nuclear option)
git_nuke() {
echo -e "${RED}=== NUCLEAR OPTION: Hard Reset ===${NC}"
echo -e "${RED}⚠️ WARNING: This will DELETE all uncommitted changes!${NC}"
echo ""
echo -e "${BLUE}Current status:${NC}"
git status --short
echo ""
read -p "Type 'NUKE' to confirm (or anything else to cancel): " confirm
if [ "$confirm" = "NUKE" ]; then
git reset --hard HEAD
git clean -fd
echo -e "${GREEN}βœ“ Repository reset to last commit. All changes deleted.${NC}"
else
echo "Cancelled. (Phew!)"
fi
}
# Function 4: Undo multiple commits
git_whoops() {
echo -e "${YELLOW}=== Undo Multiple Commits ===${NC}"
echo ""
echo -e "${BLUE}Recent commits:${NC}"
git log --oneline -10
echo ""
read -p "How many commits to undo? " num
if ! [[ "$num" =~ ^[0-9]+$ ]]; then
echo "Invalid number. Cancelled."
return
fi
if [ "$num" -lt 1 ]; then
echo "Must be at least 1. Cancelled."
return
fi
echo ""
echo -e "${YELLOW}This will undo the last $num commit(s) but keep changes.${NC}"
read -p "Continue? (y/n): " -n 1 -r
echo
if [[ $REPLY =~ ^[Yy]$ ]]; then
git reset --soft HEAD~$num
echo -e "${GREEN}βœ“ Undone $num commit(s)! Changes are still staged.${NC}"
else
echo "Cancelled."
fi
}
# Function 5: Remove large file from last commit
git_remove_file() {
echo -e "${YELLOW}=== Remove File from Last Commit ===${NC}"
echo ""
echo -e "${BLUE}Files in last commit:${NC}"
git diff-tree --no-commit-id --name-only -r HEAD
echo ""
read -p "Enter filename to remove: " filename
if [ -z "$filename" ]; then
echo "No filename provided. Cancelled."
return
fi
git rm --cached "$filename" 2>/dev/null
if [ $? -eq 0 ]; then
git commit --amend --no-edit
echo -e "${GREEN}βœ“ Removed $filename from last commit${NC}"
echo -e "${BLUE}Don't forget to add it to .gitignore if needed!${NC}"
else
echo -e "${RED}Error: Could not remove $filename${NC}"
fi
}
# Main menu
show_menu() {
clear
echo -e "${BLUE}╔════════════════════════════════════╗${NC}"
echo -e "${BLUE}β•‘ Git Oops Toolkit πŸ› οΈ β•‘${NC}"
echo -e "${BLUE}β•šβ•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•${NC}"
echo ""
echo "1) Undo last commit (keep changes)"
echo "2) Unstage a file"
echo "3) Remove file from last commit"
echo "4) Undo multiple commits"
echo "5) πŸ’£ NUKE - Hard reset (delete all changes)"
echo "6) Exit"
echo ""
}
# Main loop
main() {
check_git_repo
while true; do
show_menu
read -p "Choose an option (1-6): " choice
echo ""
case $choice in
1) git_oops ;;
2) git_oops_file ;;
3) git_remove_file ;;
4) git_whoops ;;
5) git_nuke ;;
6) echo "Goodbye!"; exit 0 ;;
*) echo -e "${RED}Invalid option${NC}" ;;
esac
echo ""
read -p "Press Enter to continue..."
done
}
# Run the app
main