Is there a way to know or get the original create/modified timestamps?
The modified timestamp contains the time the file's data has been changed. It means when we make changes to the actual contents of the file, the file system will update the modification time.
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).
You can use the stat command to see all the timestamps of a file. Using stat command is very simple. You just need to provide the filename with it. You can see all three timestamps (access, modify and change) time in the above output.
YES, metastore or git-cache-meta can store such (meta-)information! Git by itself, without third-party tools, can't. Metastore or git-cache-meta can store any file metadata for a file.
That is by design, as metastore or git-cache-meta are intended for that very purpose, as well as supporting backup utilities and synchronization tools.
I believe that the only timestamps recorded in the Git database are the author and commit timestamps. I don't see an option for Git to modify the file's timestamp to match the most recent commit, and it makes sense that this wouldn't be the default behavior (because if it were, Makefiles wouldn't work correctly).
You could write a script to set the modification date of your files to the the time of the most recent commit. It might look something like this:
# No arguments? Recursively list all git-controlled files in $PWD and start over if [ $# = 0 ]; then git ls-files -z |xargs -0 sh "$0" exit $? fi for file in "$@"; do time="$(git log --pretty=format:%cd -n 1 \ --date=format:%Y%m%d%H%M.%S --date-order -- "$file")" if [ -z "$time" ]; then echo "ERROR: skipping '$file' -- no git log found" >&2 continue fi touch -m -t "$time" "$file" done
This accepts specific files as arguments or else updates each git-controlled file in the current directory or its children. This is done in a manner that permits spaces and even line breaks in filenames since git ls-files -z
outputs a null-terminated file list and xargs -0
parses null-terminated lists into arguments.
This will take a while if you have a lot of files.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With