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

Re: Handling renames.

From
Linus Torvalds <torvalds@osdl.org>
Date
Apr 14, 2005, 18:11 UTC
Message-ID
<Pine.LNX.4.58.0504141102430.7211@ppc970.osdl.org>
In-Reply-To
<1113501260.27227.26.camel@hades.cambridge.redhat.com>
On Thu, 14 Apr 2005, David Woodhouse wrote:
Show 6 quoted lines
>
> I've been looking at tracking file revisions. One proposed solution was
> to have a separate revision history for individual files, with a new
> kind of 'filecommit' object which parallels the existing 'commit',
> referencing a blob instead of a tree. Then trees would reference such
> objects instead of referencing blobs directly.

Please don't. It's fundamentally the git notion of "content determines objects".

It also has no relevance. A "rename" really doesn't exist in the git model. The git model really is about tracking data, not about tracking what happened to _create_ that data.

The one exception is the commit log. That's where you put the explanations of _why_ the data changed. And git itself doesn't care what the format is, apart from the git header.

So, you really need to think of git as a filesystem. You can then implement an SCM _on_top_of_it_, which means that your second suggestion is not only acceptable, it really is the _only_ way to handle this in git:

Show 8 quoted lines
> So a commit involving a rename would look something like this...
> 
> 	tree 82ba574c85e9a2e4652419c88244e9dd1bfa8baa
> 	parent bb95843a5a0f397270819462812735ee29796fb4
> 	rename foo.c bar.c
> 	author David Woodhouse <dwmw2@hades.cambridge.redhat.com> 1113499881 +0100
> 	committer David Woodhouse <dwmw2@hades.cambridge.redhat.com> 1113499881 +0100
> 	Rename foo.c to bar.c and s/foo_/bar_/g

Except I want that empty line in there, and I want it in the "free-form" section. The "rename" part really isn't part of the git header. It's not what git tracks, it was tracked by an SCM system on top of git.

So the git header is an "inode" in the git filesystem, and like an inode it has a ctime and an mtime, and pointers to the data. So as far as git is concerned, this part:

	tree 82ba574c85e9a2e4652419c88244e9dd1bfa8baa
	parent bb95843a5a0f397270819462812735ee29796fb4
	author David Woodhouse <dwmw2@hades.cambridge.redhat.com> 1113499881 +0100
	committer David Woodhouse <dwmw2@hades.cambridge.redhat.com> 1113499881 +0100

really is the filesystem "inode". The rest is whatever the filesystem user puts into it, and git won't care.

> Opinions? Dissent? We'd probably need to escape the filenames in some
> way -- handwave over that for now.

The fact that git handles arbitrary filenames (stuff starting with "." excepted) doesn't mean that the SCM above it needs to. Quite frankly, I think an SCM that handles newlines in filenames is being silly. But a _filesystem_ needs to not care.

There are too many messy SCM's out there that do not hav ea "philosophy". Dammit, I'm not interested in creating another one. This thing has a mental model, and we keep to that model.

The reason UNIX is beautiful is that it has a mental model of processes and files. Git has a mental model of objects and certain very very limited relationships. The relationships git cares about are encoded in the C files, the "extra crap" (like rename info) is just that - stuff that random scripts wrote, and that is just informational and not central to the model.

		Linus
Previous: David WoodhouseNext: David Woodhouse
Message 2 of 20 in “Handling renames.”
  1. David WoodhouseApr 14, 2005
  2. Linus TorvaldsApr 14, 2005
  3. David WoodhouseApr 14, 2005
  4. Ingo MolnarApr 14, 2005
  5. Linus TorvaldsApr 14, 2005
  6. Ingo MolnarApr 14, 2005
  7. David WoodhouseApr 14, 2005
  8. David MansfieldApr 14, 2005
  9. H. Peter AnvinApr 14, 2005
  10. Linus TorvaldsApr 14, 2005
  11. H. Peter AnvinApr 14, 2005
  12. Zach WelchApr 14, 2005
  13. Andrew Timberlake-NewellApr 14, 2005
  14. Naming the SCM (was Re: Handling renames.)Steven Cole, Apr 14, 2005
  15. Petr BaudisApr 14, 2005
  16. H. Peter AnvinApr 14, 2005
  17. Petr BaudisApr 14, 2005
  18. Peter WilliamsApr 14, 2005
  19. Daniel BarkalowApr 14, 2005
  20. David WoodhouseApr 14, 2005

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.