Restoring File Modification Times After Git Checkout
When files are checked out from git, their modification time (mtime) is set to the checkout time rather than their original modification time. This affects features that rely on file modification times, such as "updated since" search filters.
Solution: git-restore-mtime
The git-restore-mtime tool restores file modification times based on git commit history.
Installation
# Ubuntu/Debian
sudo apt install git-restore-mtime
# macOS (via Homebrew)
brew install git-restore-mtime
# pip (cross-platform)
pip install git-restore-mtime
Usage
After checking out a repository or branch:
git restore-mtime
Example: Bash Function
git.restore_modification_mtime () {
echo.func "${@}";
local dir="${1:-${PWD:?}}";
git -C ${dir:?} restore-mtime || {
echo.yellow "Failed to restore modification time.";
return 1
}
}
When to Use
- After
git clone - After
git checkout(switching branches) - After
git pull(if files were modified) - Before using Thorg's "updated since" search filters
Backlinks