Working on local master branch:
git commit -m "Lots of important commits"
git reset --hard origin/master
How can I retrieve the commits that have been lost as a result of the git reset (from the remote)?
EDIT: note this is not about retrieving uncommitted changes.
If you have the reference of the commit, you can just git reset --hard <sha> to that precise commit. In case you don't you can always use git reflog to retrieve the sha before performing the hard reset.
We can use the command git fsck to recover the files after a hard reset.
There is no command to explicitly undo the git pull command. The alternative is to use git reset, which reverts a repository back to a previous commit.
If you committed it, nothing is lost.
If you have the reference of the commit, you can just git reset --hard <sha>
to that precise commit.
In case you don't you can always use git reflog
to retrieve the sha before performing the hard reset.
For instance if git reset --hard origin/master
is the last command you run, you can do
git reset HEAD@{1}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With