tags:

views:

140

answers:

3

This might seem like a weird question, but bear with me.

I'd like to (ab?)use git for a little project I'm working on, where I'd like to branch a file, yet keep the branched file within the current branch under a new name, maintaining history (allowing me to rebase changes to the original). This is similar to Subversion I suppose, in that Subversion doesn't know branches, and just copies.

I'd like to have documents which doubles as document templates (these are plain text files, don't worry merging will be quite possible), and in order to base a new document on another document, I'd like to just branch it.

Is this at all possible with Git? If not (and I'm actually assuming it's not, given Git's structure), are there any conceivable alternatives? I don't want to move away from Git, though, as I use it for much more, so if there's no good solution, I guess I can live with implementing my own (lightweight) branch/rebase on top of it.

+1  A: 

What's so wrong with branching? You could pretty easily maintain a "templates" branch and move your changed documents between them.

Say, for example:

git checkout -b templates
git checkout master
git checkout templates path/to/template.ext
cp path/to/template.ext path/to/document.ext
# decide you want to change the template
cp path/to/document.ext path/to/template.ext
git commit -a -m "changed template"
git checkout templates
git merge master
Jim Puls
yeah, I might have to resort to doing it this way (that's what I meant by my own branch/rebase). The problem with this approach is that there's no way of knowing which template the document was based on (and which template that template was based on, and so on), so I'd still have to implement my own scheme for performing the correct rebase when documents along the chain are changed.
roe
A: 

You could conceivably mount the same submodule at different places in the directory tree, with different versions mounted. The filename would bethe same, but with different versions. I'm not sure I'd like to be the one maintaining that stuff, though.

krosenvold
+1  A: 

git will detect copies of a file for you and track history correctly on them.

Maybe I'm not understanding what you are asking?

  • Is it that you want to be able to modify the template file and have the "branched" file reflect the changes?
  • Is it just that you want to be able to track which files came from which templates?
Jeremy Wall
I want to track what files came from what template/file, and be able to merge those changes into the file. As far as I can tell, git only tracks branches, copying a file is the same as writing a new file with a different name, or is there a way to tell git this was in fact a copy of x?
roe
then git does this for you behind the scenes. You don't have to tell git this file is a copy of x it already knows it's a copy of x just from the content of the file. Git autodetects file copies. It also autodetects content that moves from one file to the next. Use git diff -M and git show -M to test this but it should show that the file was copied.
Jeremy Wall
I suppose git tracks content, not files. So no tracking going on between file names, just content, and it's going to be very hard to tell if that's good enough in this case. http://stackoverflow.com/questions/1537616/handling-renames-svn-vs-git-vs-mercurial
roe