Reputation: 2051
So I did some commits locally without pushing anything and at one point I've deleted some files and committed that. After some other commits I've decided to rollback with a series of git reset HEAD~1
.
I've maybe went too far with the reset and get past the actual commit that deleted the files (I kept resetting because I didn't see any files yet). Now I'm at this point: the latest commit was made when the files where still there but I still don't see any changes on disk. Any actions I can perform to bring back that data?
Checking out the latest push would not work because these files have never been pushed once.
bernardo@MS-7821 ➜ agora git:(main) ✗ git reset HEAD~1
Unstaged changes after reset:
M .gitignore
D include/agora/cluster_launcher.hpp
D include/agora/doe_launcher.hpp
D include/agora/launcher.hpp
D include/agora/model_launcher.hpp
D src/cluster_launcher.cpp
D src/doe_launcher.cpp
D src/launcher.cpp
M src/main.cpp
D src/model_launcher.cpp
bernardo@MS-7821 ➜ agora git:(main) ✗ git reset HEAD~1
Unstaged changes after reset:
D include/agora/cluster_launcher.hpp
D include/agora/doe_launcher.hpp
D include/agora/launcher.hpp
D include/agora/model_launcher.hpp
D include/agora/prediction_launcher.hpp
D src/cluster_launcher.cpp
D src/doe_launcher.cpp
D src/launcher.cpp
M src/main.cpp
D src/model_launcher.cpp
bernardo@MS-7821 ➜ agora git:(main) ✗ git reset HEAD~1
Unstaged changes after reset:
M .gitignore
D include/agora/cluster_launcher.hpp
D include/agora/doe_launcher.hpp
D include/agora/launcher.hpp
D include/agora/model_launcher.hpp
D src/cluster_launcher.cpp
D src/doe_launcher.cpp
D src/launcher.cpp
M src/main.cpp
D src/model_launcher.cpp
bernardo@MS-7821 ➜ agora git:(main) ✗ git reset HEAD~1
Unstaged changes after reset:
M .gitignore
M src/main.cpp
Here's the reflog:
bafed80 (HEAD -> main) HEAD@{0}: reset: moving to HEAD~1
6efd3d2 HEAD@{1}: reset: moving to HEAD~1
2e9f946 HEAD@{2}: reset: moving to HEAD~1
84fb144 HEAD@{3}: reset: moving to HEAD~1
a86f71b HEAD@{4}: reset: moving to HEAD~1
356f96e HEAD@{5}: reset: moving to HEAD~1
c97b4f3 HEAD@{6}: commit: Launcher now has several specialization based on plugin type.
356f96e HEAD@{7}: revert: Revert "Launcher now has several specialization based on plugin type."
a86f71b HEAD@{8}: commit: Updated.
84fb144 HEAD@{9}: revert: Updated.
2e9f946 HEAD@{10}: commit (amend): Updated.
884ff20 HEAD@{11}: commit: Updated.
6efd3d2 HEAD@{12}: commit: Launcher now has several specialization based on plugin type.
bafed80 (HEAD -> main) HEAD@{13}: commit: First commit.
ed3de67 HEAD@{14}: commit: Added filesystem path support plus other major improvements.
048f777 HEAD@{15}: commit: Added doe support plus major improvements.
528f0e0 HEAD@{16}: commit: Added MQTT support plus headers/sources updates.
e803b87 (origin/main, origin/HEAD) HEAD@{17}: commit: CSV handler definitions filesystem support.
Upvotes: 1
Views: 649
Reputation: 51870
The intermediate commits will still be mentioned in your reflog :
$ git reflog
# example output from a sample repo :
9af391f (HEAD -> master) HEAD@{0}: reset: moving to HEAD~1
e2a2eb4 HEAD@{1}: reset: moving to HEAD~1
3654bb5 HEAD@{2}: reset: moving to HEAD~1
3e631d8 HEAD@{3}: commit: f.txt
3654bb5 HEAD@{4}: commit: d.txt
e2a2eb4 HEAD@{5}: commit: e.txt
9af391f (HEAD -> master) HEAD@{6}: commit: d.txt
ec80969 HEAD@{7}: checkout: moving from side1 to master
8d91c68 (side1) HEAD@{8}: commit: d.txt
2c2f479 HEAD@{9}: commit: c.txt
ec80969 HEAD@{10}: checkout: moving from master to side1
...
If you are still in the exact situation you describe in your question : the last commit which contained the files should be the one mentioned as HEAD@{1}
. Copy the hash and use it as a target :
# if you want to reset back to that commit :
git reset e2a2eb4
# if you want to get the files that were contained in that commit :
git checkout e2a2eb4 -- .
Upvotes: 1