如何迁移不再被识别为 git 存储库的旧 git 存储库?

问题描述 投票:0回答:1

我刚刚发现我有几个旧的 Git 存储库在过去十年中没有进行过修改 - 并且这些不再被识别为 Git 存储库。

其中一个无法识别的存储库包含以下文件:

drwxr-xr-x  13 jleffler  staff   416 Nov 20  2021 .git
-rw-r--r--   1 jleffler  staff    25 Nov 22  2015 .git/COMMIT_EDITMSG
-rw-r--r--   1 jleffler  staff    23 Oct 29  2015 .git/HEAD
-rw-r--r--   1 jleffler  staff    41 Nov 21  2015 .git/ORIG_HEAD
-rwxr--r--   1 jleffler  staff   137 Oct 29  2015 .git/config
-rw-r--r--   1 jleffler  staff    73 Oct 29  2015 .git/description
drwxr-xr-x  11 jleffler  staff   352 Oct 29  2015 .git/hooks
-rwxr-xr-x   1 jleffler  staff   452 Oct 29  2015 .git/hooks/applypatch-msg.sample
-rwxr-xr-x   1 jleffler  staff   896 Oct 29  2015 .git/hooks/commit-msg.sample
-rwxr-xr-x   1 jleffler  staff   189 Oct 29  2015 .git/hooks/post-update.sample
-rwxr-xr-x   1 jleffler  staff   398 Oct 29  2015 .git/hooks/pre-applypatch.sample
-rwxr-xr-x   1 jleffler  staff  1642 Oct 29  2015 .git/hooks/pre-commit.sample
-rwxr-xr-x   1 jleffler  staff  1356 Oct 29  2015 .git/hooks/pre-push.sample
-rwxr-xr-x   1 jleffler  staff  4951 Oct 29  2015 .git/hooks/pre-rebase.sample
-rwxr-xr-x   1 jleffler  staff  1239 Oct 29  2015 .git/hooks/prepare-commit-msg.sample
-rwxr-xr-x   1 jleffler  staff  3611 Oct 29  2015 .git/hooks/update.sample
-rw-r--r--   1 jleffler  staff   377 Mar 24  2017 .git/index
drwxr-xr-x   4 jleffler  staff   128 May  3  2016 .git/info
-rw-r--r--   1 jleffler  staff   240 Oct 29  2015 .git/info/exclude
-rw-------   1 jleffler  staff    59 May  3  2016 .git/info/refs
drwxr-xr-x   4 jleffler  staff   128 May  3  2016 .git/logs
-rw-r--r--   1 jleffler  staff     0 May  3  2016 .git/logs/HEAD
drwxr-xr-x   3 jleffler  staff    96 Oct 29  2015 .git/logs/refs
drwxr-xr-x   3 jleffler  staff    96 May  3  2016 .git/logs/refs/heads
-rw-r--r--   1 jleffler  staff     0 May  3  2016 .git/logs/refs/heads/master
drwxr-xr-x   4 jleffler  staff   128 May  3  2016 .git/objects
drwxr-xr-x   3 jleffler  staff    96 May  3  2016 .git/objects/info
-rw-------   1 jleffler  staff    54 May  3  2016 .git/objects/info/packs
drwxr-xr-x   4 jleffler  staff   128 May  3  2016 .git/objects/pack
-r--r--r--   1 jleffler  staff  2024 May  3  2016 .git/objects/pack/pack-9f36e2555a3014c30b8ca6b3594b4c20aec9e723.idx
-r--r--r--   1 jleffler  staff  7200 May  3  2016 .git/objects/pack/pack-9f36e2555a3014c30b8ca6b3594b4c20aec9e723.pack
-rw-r--r--   1 jleffler  staff    98 May  3  2016 .git/packed-refs

.git/config
文件的内容是:

[core]
    repositoryformatversion = 0
    filemode = true
    bare = false
    logallrefupdates = true
    ignorecase = true
    precomposeunicode = true

运行

git status
产量:

$ git status
fatal: not a git repository (or any of the parent directories): .git
$

另一个仍被识别为存储库的目录包含文件:

drwxr-xr-x  15 jleffler  staff     480 Jun  2 16:22 .git
-rw-r--r--   1 jleffler  staff     228 Oct 26  2017 .git/COMMIT_EDITMSG
-rw-r--r--   1 jleffler  staff     206 Oct 21  2017 .git/FETCH_HEAD
-rw-r--r--   1 jleffler  staff      23 Jan 18  2017 .git/HEAD
-rw-r--r--   1 jleffler  staff      41 Oct 21  2017 .git/ORIG_HEAD
-rw-r--r--   1 jleffler  staff     307 Jan 18  2017 .git/config
-rw-r--r--   1 jleffler  staff      73 Jan 18  2017 .git/description
drwxr-xr-x  12 jleffler  staff     384 Jan 18  2017 .git/hooks
-rwxr-xr-x   1 jleffler  staff     478 Jan 18  2017 .git/hooks/applypatch-msg.sample
-rwxr-xr-x   1 jleffler  staff     896 Jan 18  2017 .git/hooks/commit-msg.sample
-rwxr-xr-x   1 jleffler  staff     189 Jan 18  2017 .git/hooks/post-update.sample
-rwxr-xr-x   1 jleffler  staff     424 Jan 18  2017 .git/hooks/pre-applypatch.sample
-rwxr-xr-x   1 jleffler  staff    1642 Jan 18  2017 .git/hooks/pre-commit.sample
-rwxr-xr-x   1 jleffler  staff    1348 Jan 18  2017 .git/hooks/pre-push.sample
-rwxr-xr-x   1 jleffler  staff    4951 Jan 18  2017 .git/hooks/pre-rebase.sample
-rw-r--r--   1 jleffler  staff     544 Jan 18  2017 .git/hooks/pre-receive.sample
-rwxr-xr-x   1 jleffler  staff    1239 Jan 18  2017 .git/hooks/prepare-commit-msg.sample
-rwxr-xr-x   1 jleffler  staff    3610 Jan 18  2017 .git/hooks/update.sample
-rw-r--r--   1 jleffler  staff   13334 Jun  2 16:09 .git/index
drwxr-xr-x   4 jleffler  staff     128 Nov 11  2018 .git/info
-rw-r--r--   1 jleffler  staff     240 Jan 18  2017 .git/info/exclude
-rw-r--r--   1 jleffler  staff     641 Nov 11  2018 .git/info/refs
drwxr-xr-x   4 jleffler  staff     128 Nov 11  2018 .git/logs
-rw-r--r--   1 jleffler  staff       0 Nov 11  2018 .git/logs/HEAD
drwxr-xr-x   4 jleffler  staff     128 Jan 18  2017 .git/logs/refs
drwxr-xr-x   3 jleffler  staff      96 Nov 11  2018 .git/logs/refs/heads
-rw-r--r--   1 jleffler  staff       0 Nov 11  2018 .git/logs/refs/heads/master
drwxr-xr-x   3 jleffler  staff      96 Jan 18  2017 .git/logs/refs/remotes
drwxr-xr-x   4 jleffler  staff     128 Nov 11  2018 .git/logs/refs/remotes/origin
-rw-r--r--   1 jleffler  staff       0 Nov 11  2018 .git/logs/refs/remotes/origin/HEAD
-rw-r--r--   1 jleffler  staff       0 Nov 11  2018 .git/logs/refs/remotes/origin/master
drwxr-xr-x   4 jleffler  staff     128 Nov 11  2018 .git/objects
drwxr-xr-x   3 jleffler  staff      96 Nov 11  2018 .git/objects/info
-rw-r--r--   1 jleffler  staff      54 Nov 11  2018 .git/objects/info/packs
drwxr-xr-x   4 jleffler  staff     128 Nov 11  2018 .git/objects/pack
-r--r--r--   1 jleffler  staff    8660 Nov 11  2018 .git/objects/pack/pack-d5c4ff545cf0c5c55c767d2d20a5a947fc9e980e.idx
-r--r--r--   1 jleffler  staff  117736 Nov 11  2018 .git/objects/pack/pack-d5c4ff545cf0c5c55c767d2d20a5a947fc9e980e.pack
-rw-r--r--   1 jleffler  staff     621 Nov 11  2018 .git/packed-refs
drwxr-xr-x   3 jleffler  staff      96 Nov 20  2021 .git/refs
drwxr-xr-x   3 jleffler  staff      96 Jan 18  2017 .git/refs/remotes
drwxr-xr-x   3 jleffler  staff      96 Nov 11  2018 .git/refs/remotes/origin
-rw-r--r--   1 jleffler  staff      32 Jan 18  2017 .git/refs/remotes/origin/HEAD

.git/config
文件包含:

[core]
    repositoryformatversion = 0
    filemode = true
    bare = false
    logallrefupdates = true
    ignorecase = true
    precomposeunicode = true
[remote "origin"]
    url = [email protected]:jleffler/scc-snapshots
    fetch = +refs/heads/*:refs/remotes/origin/*
[branch "master"]
    remote = origin
    merge = refs/heads/master

git status
的输出是:

$ git status
On branch master
Your branch is up to date with 'origin/master'.

nothing to commit, working tree clean

我不确定显着差异是什么。

  • 你能确定问题出在哪里吗?
  • 除了下载旧版本的 Git、构建并运行它之外,有没有办法解决这个问题?
  • 这是否可以解决问题——或者我只需要一次重建一个签入历史记录,在使用旧 Git 的旧存储库和使用当前系统提供的 Git 构建的新存储库之间进行复制?

我不知道这是否重要,但我现在在配备 Apple M2 Pro 芯片的 MacBook Pro 上运行,运行 macOS Sonoma 14.5。 创建存储库时,我使用的是配备 Intel 芯片的 MacBook Pro 机器。 我怀疑这是否重要,但我现在使用

zsh
作为我之前使用
bash
的 shell。

Git 的当前版本是

/usr/bin/git
,它报告版本“git version 2.39.3 (Apple Git-146)”。

git macos
1个回答
0
投票

我将建议一个非常简单的解决方案。假设您正在查看的是一个 bare 存储库,已删除其

refs
目录。然后你可以像这样解决问题:

  • 手动为麻烦的
    .git
    目录提供一个
    refs
    子目录。
  • 手动为该
    refs
    子目录提供一个
    heads
    子目录和一个
    tags
    子目录。

enter image description here

这些目录将为空。尽管如此,这应该足以让 Git 将其视为 Git 存储库;你可以很容易地检验这个假设。

如果that有效,则在其他地方创建一个新的空文件夹,

cd
放入其中,然后说

git clone /path/to/that/.git

结果将是一个可用的工作树。

© www.soinside.com 2019 - 2024. All rights reserved.