git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: Branches & directories

From
Jeff King <peff@peff.net>
Date
Oct 3, 2011, 07:30 UTC
Message-ID
<20111003073059.GA9455@sigill.intra.peff.net>
In-Reply-To
<CAE1pOi2xmVHrVJcC85wvCv=anhn_kYizyUMpUVZF4EE33RoGmg@mail.gmail.com>
On Mon, Oct 03, 2011 at 12:15:33AM -0700, Hilco Wijbenga wrote:
Show 14 quoted lines
> On 2 October 2011 20:07, Jeff King <peff@peff.net> wrote:
> <snip/>
> > Or did you really mean your example literally, as in you run two
> > checkouts back to back, without running anything in between, and the
> > second checkout restores the state before the first one. In that case,
> > yes, it would be correct to keep the old timestamps. But this is an
> > optimization that can only apply in a few very specific cases. And
> > moreoever, how can git know when it is OK to apply that optimization? It
> > has no idea what commands you might have run since the last time we were
> > at "master".
> 
> Yes, I meant it literally. And, no, Git could not possibly know so it
> would have to be optional behaviour. But it's probably a lot of work
> for (for most people) little gain.

If you really want the human to trigger it, then you can do something like this:

  cat >git-checkout-timestamp <<\EOF
  #!/bin/sh
  old=`git rev-parse HEAD`
  git checkout "$@" || exit 1
  time=`git log -1 --format=%at`
  git diff-tree --name-only -z "$old" HEAD |
    perl -0ne "utime($time, $time, \$_)";
  EOF

Drop that somewhere in your $PATH, and use it instead of regular checkout. It restores the timestamps on any changed files, but not on those that were not touched. So your:

  git checkout branch
  git checkout master

example would end up with timestamps set for "master" on the changed files. Two caveats:

  1. This can still break makefiles! For example, like this:
       make foo.o ;# now foo.o is recent
       vi foo.c   ;# but foo.c is _more_ recent
       git checkout branch ;# now it's even newer
       git checkout-timestamp master ;# now we've restored it to some
                                     ;# old timestamp, and make will
                                     ;# think it's older than foo.o
  2. In general, I'm not sure it makes any sense if there are local
     worktree modifications to the files in question. But I didn't think
     about it too hard. That ways madness lies.
-Peff
Previous: Hilco WijbengaNext: Matthieu Moy
Message 42 of 52 in “Branches & directories”
  1. Hilco WijbengaAug 17, 2011
  2. Evan ShelhamerAug 17, 2011
  3. Junio C HamanoAug 17, 2011
  4. Hilco WijbengaAug 17, 2011
  5. Jonathan NiederAug 18, 2011
  6. Hilco WijbengaAug 21, 2011
  7. Michael WittenAug 18, 2011
  8. Michael J GruberAug 18, 2011
  9. Michael WittenAug 18, 2011
  10. Jonathan NiederAug 19, 2011
  11. Hilco WijbengaAug 21, 2011
  12. Michael WittenAug 21, 2011
  13. Hilco WijbengaAug 21, 2011
  14. Michael WittenAug 21, 2011
  15. Hilco WijbengaAug 21, 2011
  16. Michael WittenAug 22, 2011
  17. Hilco WijbengaAug 22, 2011
  18. Hilco WijbengaAug 22, 2011
  19. Michael WittenAug 22, 2011
  20. Hilco WijbengaAug 22, 2011
  21. Kyle MoffettAug 22, 2011
  22. Hilco WijbengaAug 22, 2011
  23. Kyle MoffettAug 22, 2011
  24. Hilco WijbengaAug 22, 2011
  25. Kyle MoffettAug 22, 2011
  26. Hilco WijbengaAug 22, 2011
  27. Restoring timestamps (Re: Branches & directories)Jonathan Nieder, Aug 22, 2011
  28. Hilco WijbengaAug 22, 2011
  29. Jonathan NiederAug 22, 2011
  30. Hilco WijbengaAug 23, 2011
  31. Hilco WijbengaAug 23, 2011
  32. Enrico WeigeltOct 2, 2011
  33. Hilco WijbengaOct 2, 2011
  34. Michael WittenAug 23, 2011
  35. Robin RosenbergOct 2, 2011
  36. Ronan KeryellOct 2, 2011
  37. Matthieu MoyOct 2, 2011
  38. Hilco WijbengaOct 2, 2011
  39. Hilco WijbengaOct 2, 2011
  40. Jeff KingOct 3, 2011
  41. Hilco WijbengaOct 3, 2011
  42. Jeff KingOct 3, 2011
  43. Matthieu MoyOct 3, 2011
  44. Jeff KingOct 3, 2011
  45. Matthieu MoyOct 3, 2011
  46. Jeff KingOct 3, 2011
  47. Junio C HamanoOct 3, 2011
  48. Jeff KingOct 3, 2011
  49. Hilco WijbengaOct 3, 2011
  50. Robin RosenbergOct 3, 2011
  51. Hilco WijbengaOct 3, 2011
  52. Hilco WijbengaOct 2, 2011

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.