On Tue, 18 Dec 2012 10:37:47 -0500
wor...@alum.mit.edu (Dale R. Worley) wrote:

> > In general, it's impossible to copy a file from one branch to
> > another, preserving its history.
> It must be *possible* to do that:  You could do a merge between the
> head of A and the head of B, where all of the files of A are carried
> into the merged version, and only the one file of B is carried into
> the merged version.  The question is how to do that without needing
> 1,000 commands.

What I meant, is that in certain VCS, namely Subversion,
the history of any given file is *implemented* -- both as a
concept and physically.
I mean, `svn cp branch1/filename branch2/filename` would copy only that
one file from branch1 to branch2, and its (full) history will still be
traceable from its new copy in branch2.

Since Git only records snapshots of whole trees and does not really
track individual files, there's no such *concept* as the history of an
individual file -- it might appear to exist (thanks to the
`git log ... <filename>` command) but it's implemented as a filter
applied to the regular line of history plus the trickery named "rename
detection" which uses heuristics (controlled by certain knobs).

So yes, it's possible to invent hacks to take a branch, rewrite each
commit on it to only leave that single file in them and then merge that
line of history to the target branch, but they will still remain hacks.

And there's more to it, actually.  Inability to copy a file with its
full history between branches was my pet peeve when I were starting
with Git (and my first question to this list was about this, by the
way).  But later, when I got accustomed to the model of snapshots
exercised by most (if not all) DVCSes that pet hate was seriously
undermined: cases when a file receives very localised changes when
it gets changed as a part of a project are actually rare.  I mean, the
line of history of a single file ripped from the line of history of a
project that file is a part of might not have much sense, at least
certain commits of it might not have much sense.  Namely, certain
changes might appear in that file as coming out of thin air or
disappearing to nowhere while in fact they were moved in from some other
file and then moved away into some other file, respectively.
I'm still ambivalent on this issue: there are both logical pros and
cons of the ability to copy a file with its full history between

By the way, [1] contains a good summary of the question being discussed.

1. http://markpasc.livejournal.com/186489.html


Reply via email to