Issue
Just before I committed, I had staged all my changes by using git ..
(I was in a sub directory) and I had run git status to see the staged changes. Git had staged only the changed files at that point, just as expected.
In the command line, I run git commit
with a message, get this response:
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%)
Not used to seeing the auto packing message, though I’ve found other articles that could help me get rid of it. Nevertheless, according to his cl response, the changes seem to have been committed.
Then I immediately run git status
and to my surprise, this is the response:
On branch SelectingDate
No commits yet
It then lists all files in my repository as being staged.
The files in my repo seem to be updated to their current version, which is good. Does any one know what might have happened that would have removed all commits from my current branch / how to get them back (if possible)?
Here’s the command line interaction in full:
➜ 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)
The .git directory is still present at the project root, and is more than 100mb large.
git version 2.24.3 (Apple Git-128)
result of running 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).
...
Solution
tl;dr Checkout selectingDate.
Here’s what happened.
You’re on a case-insenstive filesystem. This is important because Git can store branch names as files; .git/refs/heads/selectingDate
contains the commit ID of your selectingDate branch. At some point you did a git checkout SelectingDate
which tried to open .git/refs/heads/SelectingDate
and opened .git/refs/heads/selectingDate
instead.
This sort of works, but there’s problems. While SelectingDate will match files named selectingDate, it won’t match it in text such as .git/config which might have configuration for [branch "selectingDate"]
. Your currently checked out commit is stored in .git/HEAD which now contains ref: refs/heads/SelectingDate
.
Then git gc
happens and it packs your references. It deletes all the individual files in .git/refs and writes them in one text file .git/packed-refs
. Now the branch names are case sensitive! .git/HEAD
still says you’re on SelectingDate. Git tries to return your checkout to "SelectingDate"’s commits, but it can’t find a reference to it in .git/packed-refs
and .git/refs/heads/selectingDate
is gone. So it thinks it has no commits.
To fix this, checkout selectingDate.
If git branch
also shows SelectingDate, delete it.
If you accidentally delete both branches don’t panic. Branches are just labels. Restore the branch with git branch selectingDate 910641c4
. 910641c4 being the commit ID of your last commit to selectingDate.
See also
Answered By – Schwern
This Answer collected from stackoverflow, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0