-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathgitcleanstat
More file actions
executable file
·47 lines (33 loc) · 903 Bytes
/
gitcleanstat
File metadata and controls
executable file
·47 lines (33 loc) · 903 Bytes
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
#!/bin/bash
#
# gitcleanstat
declare usagestr=$(
cat <<EOF
$(basename $0)
Useful for resetting and cleaning up files that git reports as
"modified unmerged" or "deleted unmerged".
Runs git status to determine the state of the files, then proceeds
to clean them up by removing the "deleted unmerged" and resetting
and checking out the "modified unmerged".
\0
EOF
)
usage() {
echo -en "$usagestr"
exit 1
}
main() {
declare tempfile=/dev/shm/gitcleanstat.list
[ "$1" = "-h" ] && usage
git status -uno --porcelain > $tempfile
while read line; do
stat=$(echo $line | cut -d' ' -f1)
file=$(echo $line | cut -d' ' -f2)
[ "$stat" = "DU" ] && { echo " deleting : $file"; git rm $file; }
[ "$stat" = "UU" ] && { echo "resetting : $file"; git reset $file; git checkout $file; }
[ "$stat" = "M" ] && { echo " keeping : $file"; }
done < $tempfile
rm -f $tempfile
}
main $@
exit 0