gpt4 book ai didi

git - 为什么 git 无法识别我的本地存储库?

转载 作者:行者123 更新时间:2023-12-04 14:07:58 24 4
gpt4 key购买 nike

我刚刚跳回一个我已经使用 Git 大约 6 个月的项目,看到了这个:

$ cd /d/DEVELOP/BlenderAe # My repo root
$ git status
fatal: not a git repository (or any of the parent directories): .git
那绝对是正确的路径,为什么 git 无法识别我的本地克隆?
我最后的行动是:
  • 创建本地分支
  • 在本地分支上工作(在 VSCode 中切换到本地分支...罪魁祸首?)...
  • 已保存但未推送到远程(我再也不会错过这一步了!啊!)。

  • git文件夹内容如下:
    $ cd /d/DEVELOP/BlenderAe # My repo root
    $ ls .git
    ORIG_HEAD objects/ refs/
    我有当前的代码(在 git 之外备份它)。如何重新连接?还有我的github Remote ?

    修复后 ORIG_HEAD我懂了:
    $ git status
    Not currently on any branch.
    Changes to be committed:
    (use "git restore --staged <file>..." to unstage)
    deleted: (old_file1).py
    ...all the older files that were previously renamed/deleted are listed here for deletion.

    Untracked files:
    (use "git add <file>..." to include in what will be committed)
    Current_file1.py
    ...all the current files are listed here as untracked.

    最佳答案

    .git/HEAD失踪

    ls .git shows ORIG_HEAD objects/ refs/


    这是不完整的,比较:
    $ git init
    $ tree .git
    .git
    ├── HEAD
    ├── config
    ├── description
    ├── hooks
    │   ├── applypatch-msg.sample
    │   ├── commit-msg.sample
    │   ├── fsmonitor-watchman.sample
    │   ├── post-update.sample
    │   ├── pre-applypatch.sample
    │   ├── pre-commit.sample
    │   ├── pre-merge-commit.sample
    │   ├── pre-push.sample
    │   ├── pre-rebase.sample
    │   ├── pre-receive.sample
    │   ├── prepare-commit-msg.sample
    │   └── update.sample
    ├── info
    │   └── exclude
    ├── objects
    │   ├── info
    │   └── pack
    └── refs
    ├── heads
    └── tags

    8 directories, 16 files
    git 正在寻找以检测 git repo 的文件丢失是 HEAD .
    $ mv .git/HEAD .git/ORIG_HEAD
    $ git status
    fatal: not a git repository (or any of the parent directories): .git
    恢复 ORIG_HEAD ORIG_HEAD的存在建议 git 被留下 in the act of doing something destructive , 从中恢复(或可能看到下一个问题🤞not):
    $ mv .git/ORIG_HEAD .git/HEAD 
    $ git status
    On branch main

    No commits yet

    nothing to commit (create/copy files and use "git add" to track)
    从头开始恢复
    如果 HEAD文件丢失且没有 ORIG_HEAD文件 - 如果这是唯一的问题,它仍然可以恢复。 HEAD文件是纯文本和 indicates what branch is currently checked out :

    Usually the HEAD file is a symbolic reference to the branch you’re currently on


    例子:
    $ cat .git/HEAD
    ref: refs/heads/main
    正在创建 .git/HEAD如果 git 存储库的其他内容( main.git/objects 文件夹内容)仍然存在,则使用该内容(用任何有效的分支名称替换 .git/refs)将允许在 git 存储库上进行操作。

    关于git - 为什么 git 无法识别我的本地存储库?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/66830941/

    24 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com