4

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?

  • "push my changes without validation, or fetch and build again" Seems like you are doing something wrong. Either your branch is up-to-date with upstream and you ca just push it, or it is behind and you have to rebase/merge it and rebuild anyway (well, maybe not everything). Do you know how to specify which branches to push with `git push`? Could you write something more about your setup? Sounds unlikely that the branch you are working on is updated every 10 minutes. – Frax Mar 26 '15 at 10:36
  • Well, it is. The work with our repository isn't very well organized, unfortunately, and it is something I can hardly change. Also, I don't mind doing partial build, but if I have say makefile modified on my end then after rebase it is considered modified, causing the whole project to be rebuilt. PS: that is, even if it was built just before that – Андрей Вахрушев Mar 26 '15 at 11:05
  • 1
    Hmm, seems like you really need to do that thing with timestamps. I have some workaround which is purely git: make merge/rebase in another repository clone, then just check it out - it will update only files that really have changed. For other solution i would probably have to know something about your environment, is it linux? – Frax Mar 26 '15 at 11:41
  • 1
    I wrote my own answer, but answers [here](http://stackoverflow.com/a/3418577/2468549) and [here](http://stackoverflow.com/a/23298203/2468549) seems like they have more complete solutions. – Frax Mar 26 '15 at 12:38

1 Answers1

1

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.

Community
  • 1
  • 1
Frax
  • 5,015
  • 2
  • 17
  • 19