I have an automated build tool that uses the modification date of the file in the output. Is there a way to "git touch" the file and save that to Git without having to actually modify the file?
3 Answers
I think what you need is touch
command if you are on unix
operating system.
Git can however allow you to do a empty commit if you use --allow-empty
option.
Eg. $ git commit --allow-empty -m "Trigger notification"
would cause an empty commit which you can then push and do another deploy.
This will update the hash of the last commit without changing its message, changes, or timestamp:
git commit --amend --no-edit
-
3This would rewrite the history and require a force push. Commented Sep 25, 2019 at 17:19
-
@DavidG sure. Of course, you should not try to change the hash of already pushed commits. Commented Sep 25, 2019 at 20:01
-
5In order to change the timestamp (and hash) of the last commit,
git commit --amend --no-edit
didn't change the date of the last commit, butgit commit --amend --reset-author --no-edit
did. For more information, inman git commit
: --reset-author When used with -C/-c/--amend options, or when committing after a conflicting cherry-pick, declare that the authorship of the resulting commit now belongs to the committer. This also renews the author timestamp.– AsensiCommented Jun 10, 2020 at 10:51 -
1In order to change the timestamp of older commits, this was very useful: stackoverflow.com/questions/454734/…– AsensiCommented Jun 10, 2020 at 10:53
Git works on content hashes so it won't see your change and I doubt it has that functionality. I'd recommend that you echo the current date into that file rather than relying on modified date.
As a sideonote, relying on modification date is going to cause you many more problems as local time can be different between machines.
-
Thanks for the answer, I don't mind the local time issues since the only one that really matters is what the build machine sees, I am also only looking for the day things were modified. Commented Dec 12, 2014 at 20:55
git
doesn't even track file time stamps, except for commit time stamps, so the answer to this is going to be no.