git clone changes file modification time

后端 未结 6 1030
谎友^
谎友^ 2021-02-02 06:37

When I clone a git repository using \"git clone ...\" command all cloned files in my local repository have the same modification time with date and time when

6条回答
  •  感动是毒
    2021-02-02 07:14

    You can retrieve the last modification date of all files in a git repository. (lat commit time) https://serverfault.com/q/401437/267639

    Then use 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 my gist here.

    Oct 2019 Update

    Thanks to P. T. for your comment.
    I've updated the answer and gist to support filenames with space.

提交回复
热议问题