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

Re: Git checkout preserve timestamp?

From
Linus Torvalds <torvalds@linux-foundation.org>
Date
Mar 1, 2007, 22:25 UTC
Message-ID
<Pine.LNX.4.64.0703011409220.12485@woody.linux-foundation.org>
In-Reply-To
<17895.18265.710811.536526@lisa.zopyra.com>
On Thu, 1 Mar 2007, Bill Lear wrote:
Show 10 quoted lines
>
> I often find myself in branch A, with everything checked in and
> compiled, wanting to look at something on branch B.  I hop to branch
> B, look, and come back to branch A.  Unfortunately, when I then do a
> make, files that differed between A and B will be recompiled, as well as
> any further dependencies.
> 
> I wonder if it would be possible or desirable to have a config flag
> that told git to restore the timestamps across branch checkouts in
> order to prevent this perturbation.

I think you're much better off just using multiple repositories instead, if this is something common.

Messing with timestamps is not going to work in general. It's just going to guarantee you that "make" gets confused in a really bad way, and does not recompile *enough* instead of recompiling *too much*.

Git does make it possible to do your "check the other branch out" thing very easily, in many different ways.

You could create some trivial script that does any of the following (ranging from the trivial to the more exotic):

 - just create a new repo:
	git clone old new
	cd new
	git checkout origin/<branch>
   and there you are. The old timestamps are fine in your old repo, and 
   you can work (and compile) in the new one, without affectign the old 
   one at all.
   Use the flags "-n -l -s" to "git clone" to basically make this 
   instantaneous. For lots of files (eg big repos like the kernel), it's 
   not going to be as fast as just switching branches, but havign a second 
   copy of the working tree can be quite powerful.
 - do the same thing with just a tar-ball instead, if you want to
	git archive --format=tar --prefix=new-tree/ <branchname> |
		(cd .. ; tar xvf -)
   which is really quite fast, if you just want a snapshot.
 - get used to "git show", and just look at individual files.
   This is actually *really* useful at times. You just do
	git show otherbranch:filename
   in one xterm window, and look at the same file in your current branch 
   in another window. In particular, this should be trivial to do with 
   scriptable editors (ie GNU emacs), where it should be possible to 
   basically have a whole "dired mode" for other branches within the 
   editor, using this. For all I know, the emacs git mode already offers 
   something like this (I'm not an emacs user)
 - and in the extreme example of that "virtual directory" thing, there was 
   at least somebody working on a git plugin for FUSE, ie you could 
   literally just have virtual directories showing *all* your branches.

and I'm sure any of the above are better alternatives than playing games with file timestamps.

		Linus
Previous: Johannes SchindelinNext: Johannes Schindelin
Message 4 of 51 in “Git checkout preserve timestamp?”
  1. Bill LearMar 1, 2007
  2. Alex RiesenMar 1, 2007
  3. Johannes SchindelinMar 1, 2007
  4. Linus TorvaldsMar 1, 2007
  5. Johannes SchindelinMar 1, 2007
  6. Karl HasselströmMar 2, 2007
  7. Bill LearMar 2, 2007
  8. Bart TrojanowskiMar 2, 2007
  9. Johannes SchindelinMar 2, 2007
  10. Karl HasselströmMar 2, 2007
  11. Johannes SchindelinMar 2, 2007
  12. Karl HasselströmMar 5, 2007
  13. Johannes SchindelinMar 5, 2007
  14. Karl HasselströmMar 5, 2007
  15. Bill LearMar 5, 2007
  16. Johannes SchindelinMar 5, 2007
  17. Bill LearMar 5, 2007
  18. Johannes SchindelinMar 5, 2007
  19. Bill LearMar 5, 2007
  20. Linus TorvaldsMar 5, 2007
  21. Matthieu MoyMar 5, 2007
  22. Bill LearMar 5, 2007
  23. Linus TorvaldsMar 5, 2007
  24. Bill LearMar 5, 2007
  25. Johannes SchindelinMar 5, 2007
  26. Bill LearMar 5, 2007
  27. Johannes SchindelinMar 5, 2007
  28. Michael PooleMar 6, 2007
  29. Johannes SchindelinMar 6, 2007
  30. Michael PooleMar 6, 2007
  31. Johannes SchindelinMar 6, 2007
  32. Junio C HamanoMar 6, 2007
  33. Sergio CallegariMar 6, 2007
  34. Jakub NarebskiMar 6, 2007
  35. Bill LearMar 6, 2007
  36. Johannes SchindelinMar 6, 2007
  37. Bill LearMar 6, 2007
  38. Martin LanghoffMar 6, 2007
  39. Theodore TsoMar 6, 2007
  40. Matthieu MoyMar 5, 2007
  41. Johannes SchindelinMar 5, 2007
  42. Bill LearMar 5, 2007
  43. Johannes SchindelinMar 5, 2007
  44. Bill LearMar 5, 2007
  45. Andy ParkinsMar 5, 2007
  46. Karl HasselströmMar 5, 2007
  47. Andy ParkinsMar 5, 2007
  48. Karl HasselströmMar 5, 2007
  49. Bill LearMar 5, 2007
  50. Andy ParkinsMar 5, 2007
  51. Bill LearMar 5, 2007

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.