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.
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
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.