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