GIT recover files (git reset --hard HEAD)

Asked

Viewed 1,548 times

2

I’m a little inexperienced with GIT. I was working on a branch, but I wanted to get some updates on the master branch, but git pull failed as there were no changes committed. Then I just used the command git reset --hard HEAD. But I’d forgotten about the unmerited changes in the other branch, other than the ones I wanted to rule out. The question is, Is there any way to recover such files? Ali has several hours of work. If anyone can help me.

  • 1

    Look, I hate to bring you this kind of news, but as far as I’m concerned, there’s nothing that can be done about commited changes in git. If you were using an IDE there is a chance to find these changes in the local history.

  • Yeah, I was wondering :(

  • 1

    Yes, I am using Netbeans. I can fully recover the new files, but it seems that the modifications to existing files are not. But that’s like 65% or 70% of lost content. Thanks.

  • 1

    Hi bad mood. Works on existing files too, just right click and view the versions on Local History , find the version you want and reverse the file. Later put an answer calmly.

  • Yes, I noticed that later, apart from a change or two, I was able to recover everything. I thank you again :D

1 answer

3


Not possible. According to the documentation of git reset:

git-reset - Reset Current HEAD to the specified state

Translation: moves the pointer (the HEAD) from your last commit to the desired commit -- in this case, itself HEAD. When you run the remote with the option --hard, all pending amendments (also referred to as Working Tree) are discarded.

In the specific case of your problem, you could have run the command git stash to "save" your changes without necessarily committing them, download the changes from master, reapply your changes with git stash apply and resolve any conflicts.

  • Okay, thanks for the tip, but this time the Netbeans history saved me :D.

  • @mauhumor Boa. :)

  • It is possible to search for commits that are outside the tree: https://answall.com/a/216462/64969

Browser other questions tagged

You are not signed in. Login or sign up in order to post.