add the old snippet md files

This commit is contained in:
Travis Shears 2025-06-05 16:20:57 +02:00
parent fc0dd204c7
commit bcf8313a4b
110 changed files with 3048 additions and 0 deletions

View file

@ -0,0 +1,40 @@
---
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/)