Home > database >  git reset --mixed delete newly added file?
git reset --mixed delete newly added file?

Time:01-06

I'm working with git on Github with a C project. I have done the following in this order:

  1. Codding existing and new .cpp and .h files. Also added a big .stl file.
  2. Add the new files to git
  3. Create commit "A" with this changes
  4. Tried to push commit "A" to Github. It didn't let me push the commit because a file of 121MB had been added, which is more than the Github limit.
  5. Used the git reset --mixed command so that I could undo the commit "A" containing the large file, add that file to .gitignore, and recreate a commit without that file.

Now the changes contained in files that were already tracked have remained and I can re-commit them, but the newly added files in commit "A" are all gone.

Isn't the git reset --mixed command just undoing the commits without changing the files?
Is there any way to recover these files that I had just added to git and that have been deleted?

CodePudding user response:

Apparently, the action that hides behind your IDE's "reset commit" isn't git reset --mixed, and it resulted in files being deleted from your disk.


As said in the comments : you can use the reflog to find past commits.

  • run git reflog to spot the sha for commit A (the faulty commit with the 121MB file)

  • use whatever action you see fit to get files back from that commit :

    • git reset A
    • git checkout A -- file1 file2
    • git restore -s A -W -- . or git restore -s A -W -- file1 file2
    • ...
  •  Tags:  
  • Related