Git Pre-Commit Hook-Code-Formatierung mit Teil-Commit?

Gibt es eine Möglichkeit, einen Pre-Commit-Hook zu haben, der den Code automatisch formatiert (zum Beispiel mitastyle) aber dochnicht Teil-Commit zerstören?

Arbeitsablauf:

# edit a file.txt
git add -p file.txt
# add one chunk, but not another

git commit -m 'a message'
[PRE_COMMIT_HOOK] Formatting source code

git status
# the "another" chunk is still not added

Mein Problem ist, dass wenn du agit add Innerhalb des Pre-Commit-Hooks, der erforderlich ist, nachdem das Skript den Quellcode formatiert hat, wird auch der "andere" Chunk hinzugefügt. Aber das will ich nicht.

Gibt es einen Weg, dies zu erreichen?

Antworten auf die Frage(2)

Ihre Antwort auf die Frage