Hi Eric,

I can think of two ways to do what you require:
the first is to use a shallow clone: git clone --depth 10 will only fetch 
10 commits above HEAD. Technically how it works is that if the tenth commit 
is sqy H, then it replace the parent of H by an empty commit using grafts, 
so it works as if H was the first commit in the repo.

The second one is more flexible since you can control exactly which commit 
you want in the branch is by using rebase and cherry-pick. rebase does 
exactly what you mean by "do a for loop and "replay" the change", more 
precisely cherry-pick replay the changes, and rebase calls cherry-pick for 
each commit of the branch that you specify.
The only missing point to get what you want is to start with commit E, but 
you want to erase the history leading to it. You can do that with grafts, 
but you could also do it this way:
git checkout E # we go to commit E
git checkout --orphan  clean #switch to the branch "clean". The orphan is 
here so that clean starts with 0 history
git commit -C E #recreate commit E using the same commit message in branch 
'clean', but this time it won't have parents
git rebase --onto clean E B2 #replay all commits that are after E in B2 to 
branch clean


On Friday, October 19, 2012 2:51:17 PM UTC+2, ericpar wrote:
> Hi all,
> I've been migrating our SVN repository to GIT and it went pretty 
> straightforward.
> However, due the the lack of disciplin in the SVN era, we have a repo 
> that's full of non-related stuff and cloning it takes time; most of the 
> stuff isn't required anymore.
> I'd like to sanitize my actual Git repo and I thought we actually could 
> keep the one we have for historical reasons.
> One way I thought of for getting a "clean" git repo is to create a brand 
> new one and have a branch that only covers a range of commits, say from 
> <first_SHA1>..HEAD of a given (current) branch.
> So, more graphically, I might have something like this:
> (branch B1)   A -> B -> C -> D
>                                     \
> (branch B2)                     -> E -> F -> G -> ... ->HEAD
> So I'd like to have only the branch that covers history from E to HEAD of 
> B2 in a new branch.
> The only way I can see how to do that is to program a for loop outside of 
> Git and "replay" the changes from E to HEAD of B2. But I'm not even sure to 
> know how I'd find that.
> Can cherry-pick be of any help?
> Cheers,
> Eric

You received this message because you are subscribed to the Google Groups "Git 
for human beings" group.
To view this discussion on the web visit 
To post to this group, send email to git-users@googlegroups.com.
To unsubscribe from this group, send email to 
For more options, visit this group at 

Reply via email to