fix git file mode changes - 06-04-22
Before changing laptops I backed up all my personal projects to my NAS. When I transfer them back the file modes got messed up and a git status returned this:
diff --git a/docker/Dockerfile b/docker/Dockerfile
old mode 100644
new mode 100755
diff --git a/lib/DeployTool/CLI.rakumod b/lib/DeployTool/CLI.rakumogpg --list-secret-keys --keyid-format LONG <EMAIL>d
old mode 100644
new mode 100755
diff --git a/lib/DeployTool/Config.rakumod b/lib/DeployTool/Config.rakumod
old mode 100644
new mode 100755
Git diff shell magic, thanks to Stanislav Khromov, to the rescue!
$ git diff -p -R --no-ext-diff --no-color \
| grep -E "^(diff|(old|new) mode)" --color=never \
| git apply
This command uses git diff and some clever grep logic to swap the file modes back to what git remembers them as.
I also converted the snippet to a shell script here
source: Stanislav Khromov’s blog
\- [
git
]