1.3 KiB
1.3 KiB
| title | seo_description | date | draft | snippet_types | |
|---|---|---|---|---|---|
| fix git file mode changes | How to reset file modes via git diff. | 2022-06-04T12:16:22+02:00 | false |
|
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