git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: <ncrfgs@tin.it>
To: git@vger.kernel.org
Cc: madewokherd@gmail.com, ncrfgs@tin.it
Subject: making a branch with just one file and keeping its whole history
Date: Mon, 21 Jul 2008 06:18:04 +0200	[thread overview]
Message-ID: <20080721061804.223f7801@mail.tin.it> (raw)

[-- Attachment #1: Type: text/plain, Size: 3664 bytes --]

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@irc.freenode.net 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@irc.freenode.net 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 #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 197 bytes --]

             reply	other threads:[~2008-07-21  4:24 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-07-21  4:18 ncrfgs [this message]
2008-07-21 16:19 ` making a branch with just one file and keeping its whole history Eric Raible
2008-07-21 18:08   ` Johannes Schindelin
2008-07-21 18:22     ` Eric Raible
2008-07-21 18:39       ` Johannes Schindelin
2008-07-22  2:14         ` extracting the history of a single file as a new project [Was: Re: making a branch with just one file and keeping its whole] ncrfgs
2008-07-22  6:15           ` Sverre Rabbelier

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20080721061804.223f7801@mail.tin.it \
    --to=ncrfgs@tin.it \
    --cc=git@vger.kernel.org \
    --cc=madewokherd@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).