Created
November 14, 2011 14:13
-
-
Save petr999/1364021 to your computer and use it in GitHub Desktop.
commits filter doesn't detach history
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ mkdir test00 && cd test00 | |
$ git init && dd if=/dev/random bs=1m count=1 > test00.txt && git add test00.txt && git commit -a -m init | |
Initialized empty Git repository in /tmp/test01/test00/.git/ | |
1+0 records in | |
1+0 records out | |
1048576 bytes transferred in 0.072885 secs (14386712 bytes/sec) | |
[master (root-commit) 4a45d69] init | |
1 files changed, 0 insertions(+), 0 deletions(-) | |
create mode 100644 test00.txt | |
$ dd if=/dev/random bs=1m count=1 >> test00.txt && git commit -a -m 'commit 00' | |
1+0 records in | |
1+0 records out | |
1048576 bytes transferred in 0.139216 secs (7532011 bytes/sec) | |
[master b3b1f3d] commit 00 | |
1 files changed, 0 insertions(+), 0 deletions(-) | |
$ dd if=/dev/random bs=1m count=1 >> test00.txt && git commit -a -m 'commit 01' | |
1+0 records in | |
1+0 records out | |
1048576 bytes transferred in 0.085511 secs (12262474 bytes/sec) | |
[master e3d44c2] commit 01 | |
1 files changed, 0 insertions(+), 0 deletions(-) | |
$ tail -c 1048576 < test00.txt > test01.txt && mv -v test01.txt test00.txt && git commit -a -m 'commit 02' | |
test01.txt -> test00.txt | |
[master 58c8eaf] commit 02 | |
1 files changed, 4032 insertions(+), 12200 deletions(-) | |
rewrite test00.txt (66%) | |
$ dd if=/dev/random bs=1m count=1 >> test00.txt && git commit -a -m 'commit 03' | |
1+0 records in | |
1+0 records out | |
1048576 bytes transferred in 0.109517 secs (9574542 bytes/sec) | |
[master e94b14f] commit 03 | |
1 files changed, 0 insertions(+), 0 deletions(-) | |
$ dd if=/dev/random bs=1m count=1 >> test00.txt && git commit -a -m 'commit 04' | |
1+0 records in | |
1+0 records out | |
1048576 bytes transferred in 0.126308 secs (8301741 bytes/sec) | |
[master f875d2b] commit 04 | |
1 files changed, 0 insertions(+), 0 deletions(-) | |
$ git rev-list --all | perl -Mstrict -wE 'my $i = 0; while( <> ){ $i++; print unless $i > 2; }' > ../fresh.lst | |
$ git filter-branch -f --commit-filter "$PWD/../test00.pl $PWD/../fresh.lst" | |
Rewrite f875d2b27cb687470e8331bf8ce22f9e17e51f7e (6/6) | |
WARNING: 'refs/heads/master' was rewritten into multiple commits: | |
f875d2b27cb687470e8331bf8ce22f9e17e51f7e [0/678] | |
e94b14fd4ee3ec035f84e27ada4185b123c31d1d | |
WARNING: Ref 'refs/heads/master' points to the first one now. | |
$ cat ../test00.pl | |
#!/usr/bin/env perl | |
use v5.14; # use strict; use feature 'say'; | |
use warnings; | |
use File::Slurp; | |
# use Data::Dump; warn ddx \@ARGV; | |
my %h = map { $_ => 1 } read_file $ARGV[0]; | |
while (<>) { | |
chomp; | |
unless ( exists $h{$_} ) { say; } | |
# else { say ""; } | |
} | |
$ git log | |
commit f875d2b27cb687470e8331bf8ce22f9e17e51f7e | |
Author: Peter Vereshagin <peter@vereshagin.org> | |
Date: Mon Nov 14 18:00:25 2011 +0400 | |
commit 04 | |
commit e94b14fd4ee3ec035f84e27ada4185b123c31d1d | |
Author: Peter Vereshagin <peter@vereshagin.org> | |
Date: Mon Nov 14 18:00:17 2011 +0400 | |
commit 03 | |
commit 58c8eaf92d33115f58b5491fc31cdc5f7391ffcf | |
Author: Peter Vereshagin <peter@vereshagin.org> | |
Date: Mon Nov 14 17:59:53 2011 +0400 | |
commit 02 | |
commit e3d44c2d6fb695aa580096dd8b3545d3736a1973 | |
Author: Peter Vereshagin <peter@vereshagin.org> | |
Date: Mon Nov 14 17:58:51 2011 +0400 | |
commit 01 | |
commit b3b1f3d41be5a088a29b1e4b95b727b9a582e6ad | |
Author: Peter Vereshagin <peter@vereshagin.org> | |
Date: Mon Nov 14 17:58:47 2011 +0400 | |
commit 00 | |
commit 4a45d693b12ffb9523c1a5be706701d8aef7c762 | |
Author: Peter Vereshagin <peter@vereshagin.org> | |
Date: Mon Nov 14 17:56:56 2011 +0400 | |
init | |
! |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment