🪟 Windows TippsThe Gemini desktop app is now available for Windows(11.09.2026 um 17:06 Uhr)
🔧 AI Nachrichten ChatGPT automatically logged out [Fix](12.09.2026 um 17:09 Uhr)
🪟 Windows TippsCannot find OS partitions for disk 0 MBR2GPT Conversion failed(14.09.2026 um 00:14 Uhr)
⚠️ Malware / Trojaner / VirenWindows 11 just dropped the tool ransomware abused, Microsoft says don’t restore WMIC(10.09.2026 um 20:11 Uhr)
⚠️ Malware / Trojaner / VirenVorsicht: Android-Malware verschlüsselt Ihre Handys und nimmt heimlich Fotos auf(13.09.2026 um 09:30 Uhr)
🕵️ SicherheitslückenMicrosoft-Patchday: 966 Schwachstellen, davon 105 kritisch - BornCity(13.09.2026 um 06:31 Uhr)
🤖 Android TippsSamsung-Handys verlieren bald eine praktische App(14.09.2026 um 05:07 Uhr)
🪟 Windows TippsThe Gemini desktop app is now available for Windows(11.09.2026 um 17:06 Uhr)
🔧 AI Nachrichten ChatGPT automatically logged out [Fix](12.09.2026 um 17:09 Uhr)
🪟 Windows TippsCannot find OS partitions for disk 0 MBR2GPT Conversion failed(14.09.2026 um 00:14 Uhr)
⚠️ Malware / Trojaner / VirenWindows 11 just dropped the tool ransomware abused, Microsoft says don’t restore WMIC(10.09.2026 um 20:11 Uhr)
⚠️ Malware / Trojaner / VirenVorsicht: Android-Malware verschlüsselt Ihre Handys und nimmt heimlich Fotos auf(13.09.2026 um 09:30 Uhr)
🕵️ SicherheitslückenMicrosoft-Patchday: 966 Schwachstellen, davon 105 kritisch - BornCity(13.09.2026 um 06:31 Uhr)
🤖 Android TippsSamsung-Handys verlieren bald eine praktische App(14.09.2026 um 05:07 Uhr)

🔧 Programmierung 🕛 vor 1 Monat 4 Min Lesezeit
0

Auto-Optimize Images in a Git Pre-Commit Hook (Local, No Upload)

↗ Quelle (dev.to)
🗣️ Stimme:
📑 Inhaltsübersicht

Every repo I inherit has the same problem: someone dragged a 4.2 MB hero.png straight out of Figma into /public, committed it, and now every clone and every deploy drags that weight around forever. Git never forgets, so even after you shrink it later, the fat blob lives in history permanently.



The fix isn't "remember to compress images." Humans don't remember. The fix is a pre-commit hook that optimizes any staged image before it ever enters a commit — locally, with no upload to a third-party service.



Here's a setup you can paste in today.






The one-file version (no dependencies beyond what's already on your machine)



If you have pngquant and jpegoptim installed (both are in Homebrew and apt), this is the whole thing. Save it as .git/hooks/pre-commit and chmod +x it:




CODE
#!/usr/bin/env bash
# Optimize staged images before they enter a commit. All local, no uploads.
set -euo pipefail

# Only look at files that are staged (added/modified/copied)
staged=$(git diff --cached --name-only --diff-filter=ACM)

changed=0
while IFS= read -r file; do
[ -f "$file" ] || continue
case
"${file,,}" in
*.png)
before=$(wc -c < "$file")
pngquant --force --skip-if-larger --quality=65-90 --output "$file" -- "$file" 2>/dev/null || true
after=$(wc -c < "$file")
if [ "$after" -lt "$before" ]; then
git add "$file"; changed=1
echo " png $file $((before/1024))KB -> $((after/1024))KB"
fi
;;
*.jpg|*.jpeg)
before=$(wc -c < "$file")
jpegoptim --strip-all --max=85 --quiet "$file" || true
after=$(wc -c < "$file")
if [ "$after" -lt "$before" ]; then
git add "$file"; changed=1
echo " jpg $file $((before/1024))KB -> $((after/1024))KB"
fi
;;
esac
done <<< "$staged"

[ "$changed" -eq 1 ] && echo "Images optimized and re-staged."
exit 0






What it does:




  • Runs only on staged images, so it never rewrites files you didn't touch.


  • --skip-if-larger / the size check means it never makes a file bigger (compression can occasionally do that on already-tiny PNGs).

  • Re-stages the optimized file with git add so the smaller version is what actually gets committed.


  • strip-all removes EXIF — which also quietly deletes GPS coordinates from phone photos before they hit a public repo. (That alone has saved me from committing my home address in a screenshot's metadata.)






Make it team-wide with pre-commit



.git/hooks isn't version-controlled, so a raw hook only protects your machine. To enforce it for everyone, use the — drop an image, get a smaller one, close the tab. Same privacy property as the CLI (no upload), just without installing anything.






Takeaway



Don't rely on discipline to keep image weight out of your repo — automate it at the commit boundary. A ~30-line pre-commit hook using local tools will quietly shave megabytes off every PR, strip EXIF/GPS as a bonus, and never leak a private image to a third party. Ship the hook once; benefit on every commit forever.



If you're already doing this in CI, I'd like to hear how — especially anyone running it as a required GitHub Action gate rather than a local hook. What breaks at scale?

Vollständiger Original-Bericht
Ausführliche Details, Code-Beispiele & Hersteller-Stellungnahme auf dev.to.
↗ Original-Artikel auf dev.to lesen
Wie bewertest du diesen Beitrag?
1 Klick Feedback
Teilen mit Netzwerk & Team:

Community-Analysen & Experten-Meinungen 0

Verfasse deine eigene Analyse, teile Workarounds oder diskutiere diesen Vorfall im Blog.
Noch keine Community-Analyse verfasst. Markiere einen Textabschnitt oder klicke oben auf Eigene Analyse verfassen“!
Community Pulse: Relevanz-Einschätzung
1 Klick Experten-Votum
🔴 Akute Relevanz 0%
🟡 In Evaluierung 0%
🟢 Keine Auswirkung 0%
Spannende Innovation 0%
Verwandte Story-Cluster & Quellen (Vektor-KI)
Port 8095 Engine
1 Quelle
The Gemini desktop app is now available for Windows
1 Quelle
ChatGPT automatically logged out [Fix]
1 Quelle
Cannot find OS partitions for disk 0 MBR2GPT Conversion failed
Ähnliche Beiträge
🔍 Verwandte News

Auch interessante Nachrichten Auto-Optimize Images in a Git Pre-Commit Hook (Local, No Upload)

Thematisch verwandte Begriffe: AutoOptimize, Images, PreCommit, Hook · 6 Treffer

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...