making a branch with just one file and keeping its whole history

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi,

I have a working local repository and I'd like to make a branch with just one
file (let's say path2/filename2) and to keep its whole history.

At first I've considered creating a fresh new repo and redirecting
`git-log -p --follow path2/filename2` output to some other git command.

When later I've discussed the topic on #git@xxxxxxxxxxxxxxxx I've been pointed to
git-filter-branch.

Searching for more info about git-filter-branch on the web I've found a couple of
examples that might be close to what I'd like to accomplish:

from http://loupgaroublond.blogspot.com/2007/12/how-to-split-repository-in-git.html
	$ git filter-branch --tree-filter 'rm -rf $put_the_files_you_want_to_remove_here' HEAD
	$ git reset --hard
	$ git gc --aggressive
	$ git prune

from http://log.emmanuelebassi.net/archives/2007/09/when-the-levee-breaks/
	$ git clone --no-hardlinks /tmp/gtk2-perl Gtk2-SourceView.git
	$ git filter-branch --subdirectory-filter Gtk2-SourceView HEAD
	$ git reset --hard
	$ git gc --aggressive
	$ git prune

I've also gone through man pages and I've found something interesting:
	$ git-filter-branch --tree-filter 'rm $filename' HEAD
or, as far as I understood, equivalent and faster:
	$ git-filter-branch --index-filter 'git-update-index --remove $filename' HEAD 

Now, what I'd like to do is complementary to the above example; the difference is
that I don't want to remove just one file and its traces from history; rather I'd
like to have a new repo which includes just that file and its history.

So I would need something like the following command:
	$ git-filter-branch --tree-filter 'keep(?) $filename' HEAD

I think one possible solution would be:
	$ git-filter-branch --tree-filter 'find ! -type d | grep -v "^./path2/filename2$" | while read FILE; do rm $FILE; done' HEAD

Problems come, I think, if the content you want to keep track of, is placed in a
file that has been renamed. For example, let's say that the content you want to
keep track of was in:
	path1/filename1 from commit 1 to commit 1000
	path2/filename1 from commit 1001 to commit 2000
	path2/filename2 from commit 2001 to commit 3000

In this case I think one possible solution would be:
	$ git-filter-branch --tree-filter 'find ! -type d | grep -v "^./path1/filename1$" | grep -v "^./path2/filename1$" | grep -v "^./path2/filename2$" | while read FILE; do rm $FILE; done' HEAD

But what happens if in the meanwhile a new file has been created with one of the
names we used for the content we want to keep track of? Let's say, following the
previous case, that path2/filename1 has been renamed to path2/filename2 with
commit 2001, and that with commit 2500 a new file has been created with name
path1/filename1.

Considering both the solutions I've found on the web and the ones I've been
suggested on #git@xxxxxxxxxxxxxxxx I've found four/five possible path to follow:
	a) git log | another git command (later I've been told that git log --follows leaves out the initial revision)
	b) git clone; git filter-branch
	c) create a new repo with your one file and make an initial commit
	   then do: (cd repo-with-one-file; git ls-tree)|(cd repo-where-you-want-the-new-branch; git-mktree)
	d) git commit-tree that-tree < file-with-commit-message
	   then: git checkout -b branchname that-commit
	e) git-am or git apply processing the output of git-log or another
	   similar command

I hope you guys can help me to make some light on this issue.


Thanks in advance. :D


P.S.
Sorry for my bad english but I'm not a native english speaker, I hope that what
I've written made enough sense to you. :)

Attachment: signature.asc
Description: PGP signature


[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]

  Powered by Linux