git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: import files w/ history

From
CHCsaba Henk <csaba-ml@creo.hu>
Date
Mar 6, 2009, 13:29 UTC
Message-ID
<slrngr299k.1t4t.csaba-ml@beastie.creo.hu>
In-Reply-To
<20090303130046.GA7867@coredump.intra.peff.net>
On 2009-03-03, Jeff King <peff@peff.net> wrote:
Show 7 quoted lines
> On Tue, Mar 03, 2009 at 12:54:54PM +0000, Csaba Henk wrote:
>
>> How could I import some files from an unrelated git repo with history?
>
> Just "git pull" from the other repo, which will include all of its
> history. If you want to pretend that the other history contains just a
> subset of the true history, use "git filter-branch" to rewrite it first.

Thanks Jeff, but it didn't work well for a large repo. At least not what I could carve out myself.

The repo in question is the DragonFlyBSD repository, and I wanted to cut out the history of sys/dev/disk/vn/vn.c. After reading git-filter-branch(1) I come up with the following: first I wanted to select those commits where the file in question was modified. I tried to use the following filtration:

$ git filter-branch --commit-filter '
   if [ $# -lt 3 ] || git diff --stat $3 $1 | grep -q 'sys/dev/disk/vn/vn\.c'
   then
     git commit-tree "$@"
   else
     skip_commit "$@"
   fi' HEAD

It should select those commits where vn.c differs from the vn.c in the _first_ parent, so probably it's not exactly what I want, but anyway, I went on to give it a try.

I have even tested this filter script on a small repo and it worked well. Then I ran it against the Dfly repo, and after 23 hours of processing I ended up with:

...
23575b3e0b087120b0475ae93c505c72a9779fdb
35ac2f0aa5ac0ca78109781817c524fa354e8691
23575b3e0b087120b0475ae93c505c72a9779fdb
35ac2f0aa5ac0ca78109781817c524fa354e8691
23575b3e0b087120b0475ae93c505c72a9779fdb
35ac2f0aa5ac0ca78109781817c524fa354e8691
23575b3e0b087120b0475ae93c505c72a9779fdb
35ac2f0aa5ac0ca78109781817c524fa354e8691
23575b3e0b087120b0475ae93c505c72a9779fdb
35ac2f0aa5ac0ca78109781817c524fa354e8691
WARNING: Ref 'refs/heads/__rewrite' points to the first one now.

And the result is completely f*cked up. Neither those two commits which occur repeatedly at the end of the output, nor the commit at the actual position of the __rewrite brach has a parent, and the upstream commits from which these were derived didn't affect vn.c.

  *  *  *

OK, I then tried to do more RTFM and be more clever and efficient, and find a way to specify directly those commits which affect vn.c. As "git rev-list" can be invoked like "git rev-list <commit> <path>", and the synopsis of "git filter-branch" is like

 git filter-branch [options] [--] [<rev-list options>...]
I then gave a try to:
$ git filter-branch --  master sys/dev/disk/vn/vn.c
but no dice -- I got:
  fatal: ambiguous argument 'sys/dev/disk/vn/vn.c': unknown revision or
  path not in the working tree.
  Use '--' to separate paths from revisions
  Could not get the commits
Any idea?

Thanks, Csaba

Previous: Jeff KingNext: Miklos Vajna
Message 3 of 8 in “import files w/ history”
  1. Csaba HenkMar 3, 2009
  2. Jeff KingMar 3, 2009
  3. Csaba HenkMar 6, 2009
  4. Miklos VajnaMar 6, 2009
  5. Jeff KingMar 8, 2009
  6. Csaba HenkMar 9, 2009
  7. Jeff KingMar 10, 2009
  8. Csaba HenkMar 11, 2009

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.