Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a "git touch" so I can push the same file with a new timestamp?

Tags:

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?

like image 549
DavidGamba Avatar asked Dec 12 '14 19:12

DavidGamba


People also ask

Does git preserve file timestamps?

NO, Git simply does not store such (meta-)information, unless you use third-party tools like metastore or git-cache-meta. The only timestamp that get stored is the time a patch/change was created (author time), and the time the commit was created (committer time).

Does git save file modification time?

Git stores the last modification time for each file, based on its commit history.


2 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.

like image 161
abhishek77in Avatar answered Sep 21 '22 15:09

abhishek77in


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.

like image 29
Srdjan Grubor Avatar answered Sep 17 '22 15:09

Srdjan Grubor