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:
git checkout
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):
Updates files in the working tree to match the version in the index or the specified tree. If no paths are given, git checkout will also update
HEAD
to set the specified branch as the current branch. [...] You could omit <branch>, in which case the command degenerates to "check out the current branch" ...
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):
$ mkdir example.git
$ cd example.git
$ git init
Initialized empty Git repository in ...
$ git branch
$
There's an alternative lower-level git command that gives us the right answer:
$ git symbolic-ref --short HEAD
master
$
(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 run git checkout
with no arguments, I get the same error:
$ git checkout
fatal: You are on a branch yet to be born
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 from git fast-export
, which you directed—by name—to export only certain commits from branch ip6_dev
. Hence, I can predict that if you run git branch
you'll see:
$ git branch
ip_dev
$
This means your new repo has only the one branch, ip_dev
, which is not the branch you're on: you're on master
, which does not yet exist. Had you fast-export
ed some commit(s) on branch master
, master
would exist and you'd be able to do git 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 no master
, but now git won't complain about being unable to check it out.