I was messing about with reset
after reading stuff in the Pro Git book.
I basically ended up doing a reset --hard
to a revision 12 commits previous.
I can't seem to get back to the present, or the latest commit. I've tried reset
using ORIG_HEAD
and even feeding it in the sha1 of the revision to go forward to.
Running git status
I get:
Your branch is behind by 12 commits and can be fast-forwarded.
How do I move HEAD back to the latest commit?
Hard reset explained. In this case, you can restore the file using either git checkout or git reflog . You can find the hash-ID of the previous commit from the command: git log . In case you don't have the hash ID, you can use the command git reflog .
To undo Git reset with the –hard flag, open the Git terminal and move to the Git directory. Then, list the content of the current repository. Open and update the required file. After that, commit changes, check log history, and run the “$ git reset –hard <commit-ref>” to undo the Git reset.
Using the git reset --hard option resets the current branch tip, and also deletes any changes in the working directory and staging area. Therefore, it resets index entries to the state of the specified commit.
A hard reset can be done if you're the only one using the local and remote repository, or if the reset removes commits that have not yet been pushed to a shared remote. In this case, you're the only one affected by the hard reset, so it's relatively safe to do.
Use the reflog to find out where you want to go. You can get it using git reflog
and then just reset to the appropriate commit. Assuming you haven't done anything since you did the reset,
git reset --hard 'HEAD@{1}'
should do it.
It seems as though you've already pushed the 12 commits you reset. If that's the case, then
git merge --ff-only REMOTE/BRANCH_NAME
should work where REMOTE
is the name of the remote (commonly origin
) and BRANCH_NAME
is the name of your current branch.
Another way (beside reflog) would be to use the fact that your branch seems to be referenced on the remotes
namespace side, as a remote branch, which is why you see:
Your branch is behind by 12 commits and can be fast-forwarded.
A simple
git merge origin/yourBranch
should be enough to fast-forward the HEAD
of your local branch back to where your remote branch was.
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