1

I have a git pre-commit hook which changes some files if they are corrupt. After the hook is done the changed files are not listed in the current commit. How can I stage the changes from the hook into the current commit?

My hook looks like this:

#!/bin/sh
versionUpdater -editVersion

Which opens a windows forms where I can edit some versions from some files. After I finished editing I want that these changes are in the current commit.

Those changes from the hook are now listed in the next commit.

Kingalione
  • 4,237
  • 6
  • 49
  • 84

1 Answers1

2

There are several options. the following answer will explain in details what needs to be done and how.

Can a Git hook automatically add files to the commit?.

In the pre-commit:

  • Touch a file .processCommit or something. (be sure to add this to .gitignore)
#!/bin/sh 
echo 
touch .processCommit 
exit

In the post-commit:

if .processCommit exists you know a commit has just taken place.

#!/bin/sh
echo
if [ -a .commit ]
    then
    rm .commit
    git add yourfile
    git commit --amend -C HEAD --no-verify
fi
exit
Community
  • 1
  • 1
CodeWizard
  • 128,036
  • 21
  • 144
  • 167