When I clone a Git repository using the "git clone ...
" command, all cloned files in my local repository have the same modification time with date and time as when the git clone
command was issued.
Is there a way to clone a remote Git repository with the actual modification time for each file?
Git stores the last modification time for each file, based on its commit history.
Simply clone your project's repo twice (or even more often). When your work on a feature branch is done, simply push that branch and check it out on your 2nd copy to run tests there. You can pick up a new story and work on that on your "main" project directory.
This is an operating system issue, not a Git issue. You can get the time of the last modification from git log -n1 -- file; that is what git is for. I do not quite understand the statement "this is what git is for".
As a result, the times displayed times match the last commit that changed each file. If the file had a different timestamp on disk at the time the original commit was made, it was not ever stored anywhere in the Git repository and as such it cannot ever be restored without an external data source.
Changes that haven't been committed to the local repository are called "local" changes in Git. They exist in your Working Copy, but you haven't wrapped them in a commit, yet. If you want to discard this type of changes, you can use the git restore command: git restore index.html. This will undo all uncommitted local changes in the specified file.
Discarding Local Changes in a File Changes that haven't been committed to the local repository are called "local" changes in Git. They exist in your Working Copy, but you haven't wrapped them in a commit, yet. If you want to discard this type of changes, you can use the git restore command:
Git does not record timestamp for the files, since it is a Distributed VCS (meaning the time on your computer can be different from mine: there is no "central" notion of time and date)
The official argument for not recording that metadata is explained in this answer.
But you can find scripts which will attempt to restore a meaningful date, like this one (or a simpler version of the same idea).
You can retrieve the last modification date of all files in a Git repository (last commit time). See How to retrieve the last modification date of all files in a Git repository.
Then use the touch command change the modification date:
git ls-tree -r --name-only HEAD | while read filename; do unixtime=$(git log -1 --format="%at" -- "${filename}") touchtime=$(date -d @$unixtime +'%Y%m%d%H%M.%S') touch -t ${touchtime} "${filename}" done
Also see my gist here.
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