-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgit-modechange
More file actions
executable file
·26 lines (24 loc) · 1.03 KB
/
git-modechange
File metadata and controls
executable file
·26 lines (24 loc) · 1.03 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
#!/bin/bash
if [[ $1 == "-h" || $1 == '--help' ]]; then
echo "Usage: $0"
echo "Show files with only a mode-change and optionally revert these changes"
exit 0
fi
# Find files which have only had their filemode changed, not the content, and print out their filenames,
# then pipe this to git checkout HEAD
FILES=$(git diff --numstat | awk '{ if (($1 == "-" && $2 == "-") || ($1 == "0" && $2 == "0")) print $3 }')
if [ "x$FILES" != "x" ]; then
echo "The following files have had their modes changed, but not their content:"
git diff --numstat | awk '{ if (($1 == "-" && $2 == "-") || ($1 == "0" && $2 == "0")) print $3 }'
echo -e -n "\n\nRevert these files to HEAD version (y/N) ? "
read X
if [ "$X" = "y" ]; then
# save all changes in case
git stash save "_gitmodechange$(date +%Y%m%d_%H%M%S)"
# Re-apply the changes before working
git stash apply
git diff --numstat | awk 'BEGIN { ORS="\0" } { if (($1 == "-" && $2 == "-") || ($1 == "0" && $2 == "0")) print $3 }' | xargs -0 git checkout HEAD
else
echo "Files left unchanged."
fi
fi