40 lines
1.3 KiB
Markdown
40 lines
1.3 KiB
Markdown
---
|
|
title: "fix git file mode changes"
|
|
seo_description: "How to reset file modes via git diff."
|
|
date: 2022-06-04T12:16:22+02:00
|
|
draft: false
|
|
snippet_types:
|
|
- git
|
|
---
|
|
|
|
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:
|
|
|
|
```shell
|
|
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](https://snippets.khromov.se),
|
|
to the rescue!
|
|
|
|
|
|
```shell
|
|
$ 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](https://paste.sr.ht/~travisshears/ee89c97e7c6a54401b28d8b71ae1f796468dcb48)
|
|
|
|
source: [Stanislav Khromov's blog](https://snippets.khromov.se/reset-file-mode-chmod-changes-when-making-a-git-commit/)
|