How to recover files added to git but overwritten by checkout
git, git-add, git-branch, git-reflog, git-revert
Solution
Okay, I fixed it. It is possible to recover files that have been added to the index. It is possible to recover the files only if they have either been added or stashed.
Here are the steps:
Step 1:
git fsck −−lost-found
This will give you a list of dangling blob IDs - the stuff you added and did not commit (before doing the force checkout)
Step 2:
git show <ID>
This is the ID associated with that dangling blob. It will spit the contents of the file to the console.
That's it!
This thread helped me: Recover from git reset --hard?
Problem
Need some help! - I added a few files using "git add " - I wanted to checkout the other files and accidentally ran "git checkout -f" I do know its possible to get these changes back using reflog etc, but I don't know how! I know it's possible to get a diff. I really need those changes. Any ideas??
Related problems
- Recover from losing uncommitted changes by "git reset --hard"
- Recovering added/staged file after doing git reset --hard HEAD^?
- Recover files that were added to the index but then removed by a git reset
- How to recover after i execute :git reset --hard HEAD
- How to list ALL git objects in the database?
- Can deleted files that are added but not committed in Git be recovered?
- Recover from losing uncommitted changes by "git reset --hard"
- How to recover after i execute :git reset --hard HEAD