Lost all my staged but uncommited modifications after git revert --abort command

后端 未结 1 1068
抹茶落季
抹茶落季 2021-01-15 18:49

I think I just totally messed up.

I\'ve been working on a project for 2 days and I was trying Magit in emacs to commit the project but I kept getting back to the sta

相关标签:
1条回答
  • 2021-01-15 19:10

    First of all make a backup of the whole folder to start with.

    Secondary : Yes you can if you have committed your files?

    Did you commit or at least git add them?

    If you did ill explain how you can find them and get them back,

    if you did not at least add them to the index then you lost them.
    Update me and ill update my answer accordingly.


    How to recover deleted files (assuming they are committed)

    The trick is to checkout the previous commit of the last good commit (this should be your revert commit in your question)

    Then checkout the version at the commit before, using the caret (^) symbol:

    git checkout <last good commit>^ 
    

    The trick is the ^ which stands for the previous commit


    I also did the git add and they were in the staging area ready to commit, but I've never passed the commit part.

    Here is a sample on how to lose my file

    So you are saved (but still you have some work in front of you.)

    1. Backup the folder (as you already did)
    2. execute git fsck --full

    How to recover my lost file

    Execute git fsck --full and then loop over the files are check to see which one is yours using the git cat-file -p <SHA>

    As you can see in the sample image i managed to recover my un-commitd file b.txt

    0 讨论(0)
提交回复
热议问题