git 快速导入不起作用
git fast-import doesn't work
我只是尝试删除特定提交背后的历史记录。我在 Git: how to remove history before a specific commit 找到以下命令:
git fast-export master~5..master | (cd ../newrepo.git && git init . && git fast-import && git checkout)
我刚刚为我的案例更改了命令(我需要分支的最后 65 次提交 ip6_dev):
git fast-export ip6_dev~65..ip6_dev | (cd ../puppet/ && git init . && git fast-import && git checkout)
当我 运行 命令时,我得到以下输出:
---------------------------------------------------------------------
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
我错过了什么?
您的 && ...
序列的最后一步是:
git checkout
注意缺少分支名称(或特定的提交 ID 或路径)。然后看看 the git checkout
documentation(我承认这有点晦涩难懂):
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" ...
因此,下一个要问的问题是:"what is the name of the current branch?" 通常情况下,人们可能会 运行 git branch
找出答案,但如果我们这样做,我们可能 什么也得不到完全(你什么也得不到,但你也不会得到标有星号的分支;见下文):
$ mkdir example.git
$ cd example.git
$ git init
Initialized empty Git repository in ...
$ git branch
$
有一个替代的低级 git 命令可以给我们正确的答案:
$ git symbolic-ref --short HEAD
master
$
(或者我们可以欺骗并查看文件.git/HEAD
)。
请注意,此时我实际上还没有 运行 git fast-import
,但是如果我 运行 git checkout
没有参数,我会得到同样的错误:
$ git checkout
fatal: You are on a branch yet to be born
那么,唯一剩下的事情就是指出 git fast-import
将按照其输入的指示导入提交(和分支),这些输入来自 git fast-export
,您按名称指示的— 仅从分支 ip6_dev
导出某些提交。因此,我可以预测,如果 you 运行 git branch
你会看到:
$ git branch
ip_dev
$
这意味着您的新仓库只有一个分支,ip_dev
,不是您所在的分支:您在master
,尚不存在。如果你 fast-export
在分支 master
上编辑了一些提交,master
会 存在并且你能够做到 git checkout
.
如果您只想拥有一个 ip_dev
分支,只需明确地检查它,以便切换当前分支。您仍然没有 master
,但现在 git 不会抱怨无法查看。
我只是尝试删除特定提交背后的历史记录。我在 Git: how to remove history before a specific commit 找到以下命令:
git fast-export master~5..master | (cd ../newrepo.git && git init . && git fast-import && git checkout)
我刚刚为我的案例更改了命令(我需要分支的最后 65 次提交 ip6_dev):
git fast-export ip6_dev~65..ip6_dev | (cd ../puppet/ && git init . && git fast-import && git checkout)
当我 运行 命令时,我得到以下输出:
---------------------------------------------------------------------
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
我错过了什么?
您的 && ...
序列的最后一步是:
git checkout
注意缺少分支名称(或特定的提交 ID 或路径)。然后看看 the git checkout
documentation(我承认这有点晦涩难懂):
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" ...
因此,下一个要问的问题是:"what is the name of the current branch?" 通常情况下,人们可能会 运行 git branch
找出答案,但如果我们这样做,我们可能 什么也得不到完全(你什么也得不到,但你也不会得到标有星号的分支;见下文):
$ mkdir example.git
$ cd example.git
$ git init
Initialized empty Git repository in ...
$ git branch
$
有一个替代的低级 git 命令可以给我们正确的答案:
$ git symbolic-ref --short HEAD
master
$
(或者我们可以欺骗并查看文件.git/HEAD
)。
请注意,此时我实际上还没有 运行 git fast-import
,但是如果我 运行 git checkout
没有参数,我会得到同样的错误:
$ git checkout
fatal: You are on a branch yet to be born
那么,唯一剩下的事情就是指出 git fast-import
将按照其输入的指示导入提交(和分支),这些输入来自 git fast-export
,您按名称指示的— 仅从分支 ip6_dev
导出某些提交。因此,我可以预测,如果 you 运行 git branch
你会看到:
$ git branch
ip_dev
$
这意味着您的新仓库只有一个分支,ip_dev
,不是您所在的分支:您在master
,尚不存在。如果你 fast-export
在分支 master
上编辑了一些提交,master
会 存在并且你能够做到 git checkout
.
如果您只想拥有一个 ip_dev
分支,只需明确地检查它,以便切换当前分支。您仍然没有 master
,但现在 git 不会抱怨无法查看。