{"thread":{"id":"14555","subject":"making a branch with just one file and keeping its whole history","startedAt":"2008-07-21T04:18:04Z","lastAt":"2008-07-22T06:15:57Z","messageCount":7,"participants":["ncrfgs@tin.it","Eric Raible","Johannes Schindelin","Sverre Rabbelier"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"84133","messageId":"20080721061804.223f7801@mail.tin.it","threadId":"14555","inReplyTo":null,"subject":"making a branch with just one file and keeping its whole history","fromName":"","fromEmail":"ncrfgs@tin.it","sentAt":"2008-07-21T04:18:04Z","receivedAt":"2008-07-21T04:18:04Z","isPatch":false,"sender":{"key":"ncrfgs@tin.it","avatar":null},"body":"Hi,\n\nI have a working local repository and I'd like to make a branch with just one\nfile (let's say path2/filename2) and to keep its whole history.\n\nAt first I've considered creating a fresh new repo and redirecting\n`git-log -p --follow path2/filename2` output to some other git command.\n\nWhen later I've discussed the topic on #git@irc.freenode.net I've been pointed to\ngit-filter-branch.\n\nSearching for more info about git-filter-branch on the web I've found a couple of\nexamples that might be close to what I'd like to accomplish:\n\nfrom http://loupgaroublond.blogspot.com/2007/12/how-to-split-repository-in-git.html\n\t$ git filter-branch --tree-filter 'rm -rf $put_the_files_you_want_to_remove_here' HEAD\n\t$ git reset --hard\n\t$ git gc --aggressive\n\t$ git prune\n\nfrom http://log.emmanuelebassi.net/archives/2007/09/when-the-levee-breaks/\n\t$ git clone --no-hardlinks /tmp/gtk2-perl Gtk2-SourceView.git\n\t$ git filter-branch --subdirectory-filter Gtk2-SourceView HEAD\n\t$ git reset --hard\n\t$ git gc --aggressive\n\t$ git prune\n\nI've also gone through man pages and I've found something interesting:\n\t$ git-filter-branch --tree-filter 'rm $filename' HEAD\nor, as far as I understood, equivalent and faster:\n\t$ git-filter-branch --index-filter 'git-update-index --remove $filename' HEAD \n\nNow, what I'd like to do is complementary to the above example; the difference is\nthat I don't want to remove just one file and its traces from history; rather I'd\nlike to have a new repo which includes just that file and its history.\n\nSo I would need something like the following command:\n\t$ git-filter-branch --tree-filter 'keep(?) $filename' HEAD\n\nI think one possible solution would be:\n\t$ git-filter-branch --tree-filter 'find ! -type d | grep -v \"^./path2/filename2$\" | while read FILE; do rm $FILE; done' HEAD\n\nProblems come, I think, if the content you want to keep track of, is placed in a\nfile that has been renamed. For example, let's say that the content you want to\nkeep track of was in:\n\tpath1/filename1 from commit 1 to commit 1000\n\tpath2/filename1 from commit 1001 to commit 2000\n\tpath2/filename2 from commit 2001 to commit 3000\n\nIn this case I think one possible solution would be:\n\t$ 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\n\nBut what happens if in the meanwhile a new file has been created with one of the\nnames we used for the content we want to keep track of? Let's say, following the\nprevious case, that path2/filename1 has been renamed to path2/filename2 with\ncommit 2001, and that with commit 2500 a new file has been created with name\npath1/filename1.\n\nConsidering both the solutions I've found on the web and the ones I've been\nsuggested on #git@irc.freenode.net I've found four/five possible path to follow:\n\ta) git log | another git command (later I've been told that git log --follows leaves out the initial revision)\n\tb) git clone; git filter-branch\n\tc) create a new repo with your one file and make an initial commit\n\t   then do: (cd repo-with-one-file; git ls-tree)|(cd repo-where-you-want-the-new-branch; git-mktree)\n\td) git commit-tree that-tree < file-with-commit-message\n\t   then: git checkout -b branchname that-commit\n\te) git-am or git apply processing the output of git-log or another\n\t   similar command\n\nI hope you guys can help me to make some light on this issue.\n\n\nThanks in advance. :D\n\n\nP.S.\nSorry for my bad english but I'm not a native english speaker, I hope that what\nI've written made enough sense to you. :)\n"},{"id":"84200","messageId":"loom.20080721T161926-61@post.gmane.org","threadId":"14555","inReplyTo":"20080721061804.223f7801@mail.tin.it","subject":"Re: making a branch with just one file and keeping its whole history","fromName":"Eric Raible","fromEmail":"raible@gmail.com","sentAt":"2008-07-21T16:19:55Z","receivedAt":"2008-07-21T16:19:55Z","isPatch":false,"sender":{"key":"raible@gmail.com","avatar":null},"body":" <ncrfgs <at> tin.it> writes:\n\n> \n> Hi,\n> \n> I have a working local repository and I'd like to make a branch with just one\n> file (let's say path2/filename2) and to keep its whole history.\n\nhttp://www.gitcasts.com/posts/empty-branches\n\n- Eric\n"},{"id":"84210","messageId":"alpine.DEB.1.00.0807211907270.8986@racer","threadId":"14555","inReplyTo":"loom.20080721T161926-61@post.gmane.org","subject":"Re: making a branch with just one file and keeping its whole history","fromName":"Johannes Schindelin","fromEmail":"johannes.schindelin@gmx.de","sentAt":"2008-07-21T18:08:57Z","receivedAt":"2008-07-21T18:08:57Z","isPatch":false,"sender":{"key":"johannes.schindelin@gmx.de","avatar":"https://avatars.githubusercontent.com/u/127790?v=4"},"body":"Hi,\n\nOn Mon, 21 Jul 2008, Eric Raible wrote:\n\n>  <ncrfgs <at> tin.it> writes:\n> \n> > I have a working local repository and I'd like to make a branch with \n> > just one file (let's say path2/filename2) and to keep its whole \n> > history.\n> \n> http://www.gitcasts.com/posts/empty-branches\n\nBeware!  This is one of the sites that triggered my mail about considering \nteaching plumbing to new users harmful.\n\nIn other words, I think that these \"git casts\" are not really the best way \nto teach Git to new users, but rather confusing.\n\nWhich is a pity, because they are nicely done otherwise.\n\nCiao,\nDscho\n"},{"id":"84216","messageId":"279b37b20807211122w3a1e0687wc84693bd95689326@mail.gmail.com","threadId":"14555","inReplyTo":"alpine.DEB.1.00.0807211907270.8986@racer","subject":"Re: making a branch with just one file and keeping its whole history","fromName":"Eric Raible","fromEmail":"raible@gmail.com","sentAt":"2008-07-21T18:22:53Z","receivedAt":"2008-07-21T18:22:53Z","isPatch":false,"sender":{"key":"raible@gmail.com","avatar":null},"body":"On Mon, Jul 21, 2008 at 11:08 AM, Johannes Schindelin\n<Johannes.Schindelin@gmx.de> wrote:\n>\n> On Mon, 21 Jul 2008, Eric Raible wrote:\n>\n>> http://www.gitcasts.com/posts/empty-branches\n>\n> Beware!  This is one of the sites that triggered my mail about considering\n> teaching plumbing to new users harmful.\n>\n> In other words, I think that these \"git casts\" are not really the best way\n> to teach Git to new users, but rather confusing.\n>\n> Which is a pity, because they are nicely done otherwise.\n>\n> Ciao,\n> Dscho\n\nI understand your concern, but if you treat that particular gitcast\nsimple as a recipe to be followed it accomplishes the goal in the\nin the most straightforward way I've seen.\n\nA new-user pure-porcelain way would be to branch then delete all\nof the files in the branch.  Which seems a bit dirty to me.\n\nOr is there some more intuitive porcelain-ish way of creating\na new empty branch that I haven't thought of?\n\n- Eric\n"},{"id":"84219","messageId":"alpine.DEB.1.00.0807211937390.8986@racer","threadId":"14555","inReplyTo":"279b37b20807211122w3a1e0687wc84693bd95689326@mail.gmail.com","subject":"Re: making a branch with just one file and keeping its whole history","fromName":"Johannes Schindelin","fromEmail":"johannes.schindelin@gmx.de","sentAt":"2008-07-21T18:39:45Z","receivedAt":"2008-07-21T18:39:45Z","isPatch":false,"sender":{"key":"johannes.schindelin@gmx.de","avatar":"https://avatars.githubusercontent.com/u/127790?v=4"},"body":"Hi,\n\nOn Mon, 21 Jul 2008, Eric Raible wrote:\n\n> On Mon, Jul 21, 2008 at 11:08 AM, Johannes Schindelin\n> <Johannes.Schindelin@gmx.de> wrote:\n> >\n> > On Mon, 21 Jul 2008, Eric Raible wrote:\n> >\n> >> http://www.gitcasts.com/posts/empty-branches\n> >\n> > Beware!  This is one of the sites that triggered my mail about considering\n> > teaching plumbing to new users harmful.\n> >\n> > In other words, I think that these \"git casts\" are not really the best way\n> > to teach Git to new users, but rather confusing.\n> >\n> > Which is a pity, because they are nicely done otherwise.\n> \n> I understand your concern, but if you treat that particular gitcast \n> simple as a recipe to be followed it accomplishes the goal in the in the \n> most straightforward way I've seen.\n\nNote, I haven't even bothered to watch that Gitcast, since it would make \nme mad again.\n\n> A new-user pure-porcelain way would be to branch then delete all of the \n> files in the branch.  Which seems a bit dirty to me.\n\nThis will not start a new branch, which is what I presume you want to do.  \nThe \"correct\" (as in: probably the best) way to do it is to make a new \ndirectory, initialize a new git repository in it, and when you have \nsomething, push that branch into the other repository.\n\nHowever, I think that the OP was talking about something completely \ndifferent: extracting the history of a single file as a new branch.\n\nCiao,\nDscho\n"},{"id":"84259","messageId":"20080722041457.52120c2f@mail.tin.it","threadId":"14555","inReplyTo":"alpine.DEB.1.00.0807211937390.8986@racer","subject":"extracting the history of a single file as a new project [Was: Re: making a branch with just one file and keeping its whole]","fromName":"","fromEmail":"ncrfgs@tin.it","sentAt":"2008-07-22T02:14:57Z","receivedAt":"2008-07-22T02:14:57Z","isPatch":false,"sender":{"key":"ncrfgs@tin.it","avatar":null},"body":"On Mon, 21 Jul 2008 20:39:45 +0200\nJohannes Schindelin <Johannes.Schindelin@gmx.de> wrote:\n\n> However, I think that the OP was talking about something completely \n> different: extracting the history of a single file as a new branch.\n\nExactly, but rather than a new branch I'd like to start a new project.\n\nI've just realized the original subject name could have been a bit\nmisleading; I took it from the description a guy on #git@freenode has\ngiven of what he thought I wanted to do, but probably I didn't explain\nmyself properly at that time.\n\n\n> This will not start a new branch, which is what I presume you want to\n> do. The \"correct\" (as in: probably the best) way to do it is to make a\n> new directory, initialize a new git repository in it, and when you\n> have something, push that branch into the other repository.\n\nAs far as I could understand, that screencast demonstrates how to create\nempty branches in Git; in other words branches that are not derivatives\nof your main branches, but entirely new projects.\n\nIn my case I don't want to start an entirely new project, but rather\nstart a new project from a file of an existing project and keeping his\nhistory.\n\n\nIn the screencast, the author creates an empty branch to store the\nwebsite code in for my project, so he doesn't have to store it as a\nsubdirectory of his main project.\n\nWhat I want to do, I think, is kinda different.\n\n\nLet's say we are at commit #3000, I have this content I want to start a\nnew project from, which has been put in three different files:\n\npath1/filename1 from commit 1 to commit 1000\npath2/filename1 from commit 1001 to commit 2000\npath2/filename2 from commit 2001 to commit 3000\n\nIn the meanwhile path1/filename1 has been created on commit 2500 with\npath1/filename1 having nothing to do with the new project I'd like to\nstart.\n\n\nMy first idea to accomplish what I'd like to do, was to use the ouput of\n`git-log -p --follow path2/filename2` with another git command; on\n#git@freenode I've been suggested to use git-clone and\ngit-filter-branch.\n\nBoth from search results on the web and from the man pages, I've found\nexamples of git-filter-branch usage which aim to delete just one file\n(or a small group of files) from the existing project's history.\n\nWhat I'd like to do instead is to keep just one file which has been\nrenamed a couple of time.\n\n\nOn #git I've been also told to use also another combination of commands\nwhich included git-commit-tree but I haven't managed to understand what\nthey meant. Another combination of commands included git-am instead.\n\n\nAny suggestion is welcome. :)\n"},{"id":"84280","messageId":"bd6139dc0807212315j4d1f1ff7rcc92077a8c70dba7@mail.gmail.com","threadId":"14555","inReplyTo":"20080722041457.52120c2f@mail.tin.it","subject":"Re: extracting the history of a single file as a new project [Was: Re: making a branch with just one file and keeping its whole]","fromName":"Sverre Rabbelier","fromEmail":"alturin@gmail.com","sentAt":"2008-07-22T06:15:57Z","receivedAt":"2008-07-22T06:15:57Z","isPatch":false,"sender":{"key":"alturin@gmail.com","avatar":null},"body":"On Tue, Jul 22, 2008 at 4:14 AM,  <ncrfgs@tin.it> wrote:\n> Let's say we are at commit #3000, I have this content I want to start a\n> new project from, which has been put in three different files:\n>\n> path1/filename1 from commit 1 to commit 1000\n> path2/filename1 from commit 1001 to commit 2000\n> path2/filename2 from commit 2001 to commit 3000\n>\n> In the meanwhile path1/filename1 has been created on commit 2500 with\n> path1/filename1 having nothing to do with the new project I'd like to\n> start.\n\n<snip>\n\n> My first idea to accomplish what I'd like to do, was to use the ouput of\n> `git-log -p --follow path2/filename2` with another git command; on\n> #git@freenode I've been suggested to use git-clone and\n> git-filter-branch.\n>\n\nIt would seem that this is a valid use-case for a properly working\n\"git log --follow\", yes?\n\n-- \nCheers,\n\nSverre Rabbelier\n"}]}