How to commit files modified by pre-commit hook in Git
You can do something like this:
#!/bin/sh
#
perl -i -pe 's/var app_version = "\d+\.\d+\.\K(\d+)/ $1+1 /e' ./version.js
git add ./version.js
What it does: It changes the string var app_version = "0.1.1"; to var app_version = "0.1.2"; and adds the file back to the git commit process. When you commit the latest change will be included.
Related videos on Youtube
dimovnike
I work with: C/C++, Java, PHP, Mysql, bash. Linux, networking. Microcontrollers (AVR, PIC) Embedded software. Also interested in: Cryptography, math, quantum Computing, photography.
Updated on September 18, 2022Comments
-
dimovnike over 1 year
Im struggling for a couple of hours to make git store metadata (permissions/flags/etc) of the files using metastore and I use
hooks/pre-commit
for this.The script is invoked correctly, and the file "metadata" is modified but not added into commit.
I tried calling:
git add ./metadata
and
git add -u ./metadata
from the pre-commit script, but there is no effect. The file ends up uncommited and marked as modified or staged BUT not commited, ever.
Is there any way to make this work? Basically, I want it to update and commit the file "metadata" on each commit (preferably, as the same commit, so I can restore all permissions after checkout)
Thanks!
P.S. If you are wondering why I need this, the answer is I store OS files for an embedded device which needs permisions/suid flags etc.
-
Arkadiusz Drabczyk almost 10 yearsIt should work, maybe you are doing something wrong. Pre-commit hook is executed automatically when you do "git commit". It must have an executable bit set. So try to add some files to the staging are manually and then do "git commit". After that do "git show" to see what changes have been introduced in this commit and see if metadata has been committed.
-
-
frhd over 9 yearsI got the same problem, but having other staged files changed doesn't solve the issue. Git doesnt pick up changes made by pre-commit in my case..
-
dimovnike over 9 yearsmake sure u do git add for the canges made by pre-commit script (at the end of the script).
-
dimovnike over 9 yearswrong question?
-
Martin Gerhardy almost 7 yearsThe problem here is that you will commit all changes in that particular file. Not only the previously staged changes. Might work for files that only contain the version though.