Git "auto packing"似乎已经从分支中删除了所有提交

标签 git

就在我提交之前,我已经使用 git .. 暂存了我的所有更改。 (我在一个子目录中)并且我运行了 git status 来查看分阶段的更改。正如预期的那样,此时 Git 仅暂存了更改的文件。
在命令行中,我运行 git commit用一条消息,得到这个回应:

Auto packing the repository in background for optimum performance.
See "git help gc" for manual housekeeping.
[SelectingDate 910641c4] Switching from many visibility animators to one translate animated view. Cuts down time to update list significantly.
 7 files changed, 43 insertions(+), 15 deletions(-)
 rename mobile/features/itemLists/CursorItemsCoordinator/{AnimatedVisibilityCursor.native.js => AnimatedTranslatingCursor.native.js} (52%)
不习惯看到自动打包消息,但我发现其他文章可以帮助我摆脱它。尽管如此,根据他的 cl 回应,似乎已经做出了更改。
然后我立即运行git status令我惊讶的是,这是回应:
On branch SelectingDate

No commits yet

然后它列出了我的存储库中的所有文件作为暂存。
我的 repo 中的文件似乎已更新为当前版本,这很好。有谁知道可能发生了什么会从我当前的分支中删除所有提交/如何将它们取回(如果可能)?
这是完整的命令行交互:
➜  mobile git:(SelectingDate) ✗ gs
On branch SelectingDate
Changes not staged for commit:
  (use "git add/rm <file>..." to update what will be committed)
  (use "git restore <file>..." to discard changes in working directory)
    deleted:    features/itemLists/CursorItemsCoordinator/AnimatedVisibilityCursor.native.js
    modified:   features/itemLists/CursorItemsCoordinator/CursorItemsCoordinator.native.js
    modified:   features/itemLists/CursorItemsCoordinator/interpolaters.native.js
    modified:   features/itemLists/MainListView/MainItemsList.native.js
    modified:   helpers/animatedIndexHelper.native.js
    modified:   ../shared/itemLists/listTypes/plan/PlanItemsContainer.shared.js
    modified:   ../web/src/__test__/native/interpolaters.test.js

Untracked files:
  (use "git add <file>..." to include in what will be committed)
    features/itemLists/CursorItemsCoordinator/AnimatedTranslatingCursor.native.js

no changes added to commit (use "git add" and/or "git commit -a")
➜  mobile git:(SelectingDate) ✗ git add ..
➜  mobile git:(SelectingDate) ✗ gs
On branch SelectingDate
Changes to be committed:
  (use "git restore --staged <file>..." to unstage)
    renamed:    features/itemLists/CursorItemsCoordinator/AnimatedVisibilityCursor.native.js -> features/itemLists/CursorItemsCoordinator/AnimatedTranslatingCursor.native.js
    modified:   features/itemLists/CursorItemsCoordinator/CursorItemsCoordinator.native.js
    modified:   features/itemLists/CursorItemsCoordinator/interpolaters.native.js
    modified:   features/itemLists/MainListView/MainItemsList.native.js
    modified:   helpers/animatedIndexHelper.native.js
    modified:   ../shared/itemLists/listTypes/plan/PlanItemsContainer.shared.js
    modified:   ../web/src/__test__/native/interpolaters.test.js

➜  mobile git:(SelectingDate) ✗ gc "Switching from many visibility animators to one translate animated view. Cuts down time to update list significantly."
Auto packing the repository in background for optimum performance.
See "git help gc" for manual housekeeping.
[SelectingDate 910641c4] Switching from many visibility animators to one translate animated view. Cuts down time to update list significantly.
 7 files changed, 43 insertions(+), 15 deletions(-)
 rename mobile/features/itemLists/CursorItemsCoordinator/{AnimatedVisibilityCursor.native.js => AnimatedTranslatingCursor.native.js} (52%)
➜  mobile git:(SelectingDate) ✗ gs
On branch SelectingDate

No commits yet

Changes to be committed:
  (use "git rm --cached <file>..." to unstage)
    new file:   ../.gitignore
    new file:   ../.prettierignore
    new file:   ../.yarn/install-state.gz
    new file:   ../README.md
    new file:   .eslintrc.json
    new file:   .expo-shared/assets.json
    new file:   .prettierrc.json
    new file:   App.native.js
    new file:   app.json
    new file:   assets/adaptive-icon.png
    new file:   assets/favicon.png
    new file:   assets/fonts/MavenProLight-200.otf
    new file:   assets/fonts/MavenProLight-300.otf
    new file:   assets/fonts/MavenProMedium.otf
    new file:   assets/fonts/maven_pro_bold-webfont.ttf
    new file:   assets/fonts/maven_pro_regular-webfont.ttf
    new file:   assets/icon.png
    new file:   assets/splash.png
    new file:   babel.config.js
    new file:   constants/colors.js
... (and all the rest of the files in my repository)

.git 目录仍然存在于项目根目录下,并且超过 100mb。
git 版本 2.24.3 (Apple Git-128)
运行结果git reflog --all
910641c4 (selectingDate) refs/heads/selectingDate@{0}: commit: Switching from many visibility animators to one translate animated view. Cuts down time to update list significantly.
f367a4d0 (refs/stash) refs/stash@{0}: WIP on SelectingDate: 37d06850 Ensures that restoreListener is readded to animatedDateValue when it is updated (and that any old one is removed).
e1437645 refs/stash@{1}: WIP on master: 193f904e Merge pull request #213 from bendelonlee/MobileGraphicCalNotes
f16f4e59 refs/stash@{2}: WIP on selectingDate: 37d06850 Ensures that restoreListener is readded to animatedDateValue when it is updated (and that any old one is removed).
37d06850 refs/heads/selectingDate@{1}: commit: Ensures that restoreListener is readded to animatedDateValue when it is updated (and that any old one is removed).
...

最佳答案

tl;dr checkout 选择日期。
这就是发生的事情。
你在一个不区分大小写的文件系统上。这很重要,因为 Git 可以将分支名称存储为文件; .git/refs/heads/selectingDate包含您的 selectionDate 分支的提交 ID。在某些时候你做了一个 git checkout SelectingDate试图打开 .git/refs/heads/SelectingDate并开通 .git/refs/heads/selectingDate反而。
这种工作,但有问题。虽然 SelectingDate 将匹配名为 selectionDate 的文件,但它不会在文本中匹配它,例如 .git/config 可能具有 [branch "selectingDate"] 的配置.您当前 checkout 的提交存储在 .git/HEAD 中,其中现在包含 ref: refs/heads/SelectingDate .
然后git gc发生并且它打包了您的引用。它删除 .git/refs 中的所有单个文件并将它们写入一个文本文件 .git/packed-refs .现在分支名称区分大小写! .git/HEAD仍然说你在 SelectingDate。 Git 尝试将您的 checkout 返回到“SelectingDate”的提交,但在 .git/packed-refs 中找不到对它的引用。和 .git/refs/heads/selectingDate离开了。所以它认为它没有提交。
要解决此问题,请 checkout 选择日期。
git branch还显示SelectingDate,删除它。
如果您不小心删除了两个分支,请不要 panic 。分支只是标签。使用 git branch selectingDate 910641c4 恢复分支. 910641c4 是您最后一次提交到 selectionDate 的提交 ID。
也可以看看

  • Git Internals - Packfiles
  • Git Internals - Git References
  • 关于Git "auto packing"似乎已经从分支中删除了所有提交,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/67270571/

    相关文章:

    html - 为什么 GitHub Pages 不将 CSS 应用到其他页面?

    node.js - 如何在 Windows 7 中删除 git 本地存储库文件夹

    git - 将问题从 Bitbucket 导入到 Github

    git - 与 `git rebase` 冲突

    git - 如何修改特定提交?

    git - 我的 VS Code SCM 装订线指示器突然出现奇怪的图案

    php - Symfony2 - 创建自己的供应商包 - 项目和 git 策略

    git - 有没有办法在 Visual Studio Team Explorer 窗口中禁用 ssl 验证?

    git - 将 git 存储库传输到 Web 服务器

    git branch 没有显示所有的分支