Avoiding/workaround for git stash/rebase changing file time stamps

My problem is, changing timestamps is causing build times to be a lot longer than they need to be, depending on which files I have modified locally. This is a headache, with our remote receiving new changes about every 10 minutes I'm forced to either push my changes without validation, or fetch and build again and again forever. Not sure which of the two I like less.

I guess this isn't something git itself should take care of, but maybe there is a tool or a script I could use to like sample files checksums and timestamps before the rebase, and then after restore the timestamps for the files whose content isn't changed?

Upvotes: 4

Views: 546

Answers (1)

Frax
Frax

Reputation: 5910

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.

Upvotes: 1

Related Questions