I just try to delete the history behind a specific commit. I found at Git: how to remove history before a specific commit the following command:
git fast-export master~5..master | (cd ../newrepo.git && git init . && git fast-import && git checkout)
I just changed the command for my case (i need the last 65 commits of the branch ip6_dev):
git fast-export ip6_dev~65..ip6_dev | (cd ../puppet/ && git init . && git fast-import && git checkout)
When I run the command i get the following output:
---------------------------------------------------------------------
Alloc'd objects: 10000
Total objects: 7985 ( 782 duplicates )
blobs : 4978 ( 0 duplicates 2304 deltas of 49
25 attempts)
trees : 2942 ( 782 duplicates 263 deltas of 29
28 attempts)
commits: 65 ( 0 duplicates 0 deltas of
0 attempts)
tags : 0 ( 0 duplicates 0 deltas of
0 attempts)
Total branches: 1 ( 1 loads )
marks: 1048576 ( 5043 unique )
atoms: 2438
Memory total: 2997 KiB
pools: 2606 KiB
objects: 390 KiB
---------------------------------------------------------------------
pack_report: getpagesize() = 65536
pack_report: core.packedGitWindowSize = 33554432
pack_report: core.packedGitLimit = 268435456
pack_report: pack_used_ctr = 358
pack_report: pack_mmap_calls = 65
pack_report: pack_open_windows = 1 / 1
pack_report: pack_mapped = 14669749 / 14669749
---------------------------------------------------------------------
fatal: You are on a branch yet to be born
What am i missing?
The very last step of your
&& ...
sequence is:Note the lack of a branch name (or specific commit ID or paths). Then take a look at the
git checkout
documentation (which I admit makes this a bit obscure):Hence, the next question to ask is: "what is the name of the current branch?" Normally one might run
git branch
to find out, but if we do that we might get nothing at all (you won't get nothing at all, but you won't get a branch marked with an asterisk either; see below):There's an alternative lower-level git command that gives us the right answer:
(or we can cheat and look at the file
.git/HEAD
).Note that I haven't actually run
git fast-import
at this point, but if I rungit checkout
with no arguments, I get the same error:The only remaining thing, then, is to point out that
git fast-import
will import commits (and branches) as directed by its input, which came fromgit fast-export
, which you directed—by name—to export only certain commits from branchip6_dev
. Hence, I can predict that if you rungit branch
you'll see:This means your new repo has only the one branch,
ip_dev
, which is not the branch you're on: you're onmaster
, which does not yet exist. Had youfast-export
ed some commit(s) on branchmaster
,master
would exist and you'd be able to dogit checkout
.If you want to have just the one
ip_dev
branch, simply check that out explicitly, so that you switch the current branch. You will still have nomaster
, but now git won't complain about being unable to check it out.