After writing my own answer I found 2 similar questions with good answers here and here. They provide python scripts for saving and restoring timestamps of files.
Below is my solution. I decided to keep it because of it's simplicity - it is just bash one-liner.
It is not complete workaround, as it is a way to change all unchanged files' timestamps to some requested time and not to their previous modification date, but it should be enough for most cases. It may, however be unsafe sometimes - if you don't have your build up to date, that may prevent it from updating (ask if that is not clear).
You can list all the files that weren't changed with
git ls-files | grep -Fv '$\n'"$(git diff HEAD@{1} --name-only)"
(replace HEAD@{1}
with whatever commitish you actually need)
This '$\n'
is a bit strange - it is a hack to keep it working even if no file was changed, so it is not very important.
To change modification date for all that files, use
touch -chmd "2015-03-24" $(git ls-files | grep -Fv '$\n'"$(git diff HEAD@{1} --name-only)")
(replacing HEAD@{1}
and "2015-03-24"
with whatever commit and date you want)
Beware of spaces in filenames - they are not going to work, and may cause other files to be accidentaly touched. Setting IFS='$\n'
should solve that.