From: Nick Andrew <nick@nick-andrew.net>
To: luisgutz <luis@xmos.com>
Cc: git@vger.kernel.org
Subject: Re: copy selected history between repostories
Date: Sat, 19 Jul 2008 11:01:22 +1000 [thread overview]
Message-ID: <20080719010122.GA12047@mail.local.tull.net> (raw)
In-Reply-To: <18533605.post@talk.nabble.com>
On Fri, Jul 18, 2008 at 09:58:49AM -0700, luisgutz wrote:
> Is there any way to import that directory into repoA with all it's history,
> but NOT the history from the other commits?
> Another way of putting is this: can I make git forget the history of all
> other commits but those from this directory?
I couldn't figure out git-filter-branch, so I did the following,
which worked for me:
First, export commits as patches in mbox format:
git log -p --first-parent --reverse --pretty=email $* > mbox
Second, run the mbox file through a filter which selectively
renames files (since almost always I want the files in a different
directory in the new repository):
myfilter scripts=bin perllib=lib < mbox > mbox2
Finally, import into new repo:
git-am mbox2
It's a bit slow on the import step but it meets my needs at this time.
Nick.
Filter script follows, for what it's worth ...
#!/usr/bin/perl
# @(#) git-filter-rename.pl
#
# Read an mbox file containing patches on standard input,
# modify the filenames within according to a list of substitutions
# supplied on the command line, and write the modified mbox file
# to standard output.
my @subs;
foreach (@ARGV) {
if (/(.*)=(.*)/) {
my $len = length($1);
push(@subs, [ $1, $2, $len ]);
} else {
print STDERR "Unknown arg: $_\n";
}
}
while (<STDIN>) {
chomp;
my $line = $_;
if ($line =~ /^(---|\+\+\+) ([ab]\/)(.+)$/) {
my $line_1 = $1;
my $line_2 = $2;
my $line_3 = $3;
subFilename($line_3);
print "$line_1 $line_2$line_3\n";
next;
}
if ($line =~ /^diff --git ([ab]\/)(\S+) ([ab]\/)(\S+)/) {
my ($line_1, $line_2, $line_3, $line_4) = ($1, $2, $3, $4);
subFilename($line_2);
subFilename($line_4);
print "diff --git $line_1$line_2 $line_3$line_4\n";
next;
}
print $line, "\n";
}
exit(0);
# ------------------------------------------------------------------------
# Substitute a filename in-place (modifies argument)
# ------------------------------------------------------------------------
sub subFilename {
foreach my $lr (@subs) {
my ($lhs, $rhs, $len) = @$lr;
if (substr($_[0], 0, $len) eq $lhs) {
print STDERR "Match on $lhs, $_[0]\n";
substr($_[0], 0, $len) = $rhs;
last;
}
}
}
next prev parent reply other threads:[~2008-07-19 1:02 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-07-18 16:58 copy selected history between repostories luisgutz
2008-07-18 17:12 ` Avery Pennarun
2008-07-19 1:01 ` Nick Andrew [this message]
2008-07-19 1:12 ` Johannes Schindelin
2008-07-19 1:21 ` Jeff King
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=20080719010122.GA12047@mail.local.tull.net \
--to=nick@nick-andrew.net \
--cc=git@vger.kernel.org \
--cc=luis@xmos.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).