-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrm-cached.sh
More file actions
36 lines (31 loc) · 1.12 KB
/
Copy pathrm-cached.sh
File metadata and controls
36 lines (31 loc) · 1.12 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
#!/bin/bash
# Define the path to the .gitignore file
gitignorePath=".gitignore"
# Read the .gitignore file, excluding comments and empty lines
patterns=$(grep -E -v '^\s*(#|$)' "$gitignorePath")
# Initialize an array to store skipped patterns
skippedPatterns=()
# Loop through each pattern and apply 'git rm --cached'
while IFS= read -r pattern; do
# Check if there are files matching the pattern in the git index
files=$(git ls-files "$pattern")
if [ -n "$files" ]; then
# Handle patterns ending with '/' as directory removal
if [[ "$pattern" == */ ]]; then
git rm -r --cached "${pattern%/}" > /dev/null
else
git rm --cached "$pattern" > /dev/null
fi
else
skippedPatterns+=("$pattern") # Add the skipped pattern to the array
fi
done <<< "$patterns"
# Check if there are any skipped patterns and print them
if [ ${#skippedPatterns[@]} -gt 0 ]; then
echo "No files found for the following patterns, so they were skipped:"
for pattern in "${skippedPatterns[@]}"; do
echo "- $pattern"
done
else
echo "No patterns were skipped."
fi