How to undo a Git rollback - eclipse

I wanted to rollback to the last commit after making a massive error, but I managed to rollback a little too fair. The commit I wanted to reassert doesn't appear when I enter 'git log' in bash (I suppose because it's no longer in the history). Is there any way I can recover the last commit by date?
I'm also using eGit in eclipse for the same project if that makes things easier. Thanks.

If you are ok with command line, go to you repo, do a git reflog and get the commit which you want to "rollback" to and do a git reset --hard <commit>
You would also be able to do git reset --hard HEAD#{1} and then come back to egit and rollback to the desired commit.

I find that generally it's better to make your changes forward in time rather than backward.
Git's approach is to "revert" the commit. When you revert a commit, you check out into your working directory the inverse of the commit in question. Then you add and commit that, and you've just made a NEW commit, that commits the "undoing" of the commit you're reverting, AND it leaves a record in history that such a thing happened, so if you want to undo your undoing, it's easy to do.

Related

Cancel undo commit VSCode

Accidentally I press Undo Commit and all my work dissappeared, Is there any way to revert it?
I didn't commit my last changes and that is the work I lost
As mentioned here, VSCode "Undo Last Commit" runs git reset HEAD~.
That means you can restore your last commit (but not easily your work in progress at the time of the undo) using git reflog, and a git reset --hard <lastSHA1> (again, make sure you don't have a work in progress, use git stash if needed).
However, for any work in progress, you will need the VSCode local history as mentioned in the comments.

How to undo the last commit on GitHub?

I want to undo the last commit pushed to GitHub on the master branch of a repository, and make it so that it's as if this commit never existed and doesn't appear in the commit history.
How do I go about this?
Note to those voting to close — the proposed alternative questions are needlessly complex, have condescending answers, and are littered with giant walls of text that are difficult to sift through.
Hence, this simple question with a simple answer for my benefit and that of posterity.
I think you're looking for the --force argument.
You can reset to a specific commit with git reset --hard {commit sha} and then force the change to origin with git push --force.
Note that if others are using your repo, they will need to use git pull --force or they may inadvertently put your unwanted commit back into the repo.
I recommend reading the help documentation for git reset and git push before taking action.
If you wish to rewind the master branch of the repository to a previous pushed commit, simply run this command — of course, with the appropriate commit hash:
git reset --hard a0b1c2d3e4f5g6h7i8j9k0l1m2n3o4p5q6r7s8t9
git push --force
This may have unintended consequences if, for instance, there are collaborators on your repository. But, I am sure you know what you're doing 😉

Lost a bunch of code in Github, mistakingly reverted to an old push, what are my options?

The commit no longer shows up but rather the latest one now is the one named "Instructions work".
https://images.discordapp.net/.eJwFwQEOwiAMAMC_8ABahqNlv2mYcUYpy9plica_e_cN5_EOS9jcd1sA1qe1cazRcpQun6FyWWyjg7hL2_pd3aAWKnijMuGMzFQYEiYkToyUa5pznRBOfem4NO76CL8_2w8gBg.u1qWiqmlxQgWvh_ROTa4VHx2gCY.png?format=webp
That's the screenshot of my commit. I had a merge error and googled how to resolve it and did it. Didn't notice my commit disappeared. Pressed sync thinking i was pushing my commit. Actually reverted and my commits are gone.
git revertshouldn't do anything except create a new commit -- you should be able to undo the revert by reverting to head with git revert HEAD
EDIT:
You can also search for dangling commit blobs in your lost and found history using git fsck --lost-found and then find the one you want and then apply the commit with git merge <SHA1 of commit>.
You can try reverting the actual revert commit.

Does EGit "Revert Commit" permanently delete the original commit?

I'm still learning Git's workflow for doing things, and realized that I was accidentally in the wrong working branch when I committed some files. So using EGit, I listed the commit history and selected Revert Commit from the context menu for a couple of commits.
I have since realized that I wanted those commits, but cannot find the original commits anywhere. It seems as though the original commits were all but deleted. Even doing a full log listing on the entire git repo does not show the original commit or the revert commits.
From my understanding of the EGit docs, revert commit was just supposed to "undo" the changes by creating a new commit ontop of the old one, undoing what it had done. However, it would appear that it actually deleted my original commits.
Am I toast? Did I permanently lose those changes? I'm running Eclipse 3.7 with EGit 2.1.0.20120919.
git revert, as you said, doesn't delete the commits. It only creates a new commit undoing the changes of a certain commit passed to it. So, the original commit is still in the repository. Listing the commits with git log should show the original commit and the commit that undo what the original commit does.
With that, to recover the original content of the commit, you can revert the revert commit or change your repository status to the commit before the revert with git reset --hard hash where hash represents the hash of the commit before the commits that represents your git revert.
Your best bet is to leave eclipse and egit for a while and use the commandline.
There is a tool called git reflog that can show you much more than git log. I suggest you give that a try to see what you have done to the repository.

How to delete commits with egit?

I just made some bad commits with egit that I would like to delete.
How do I delete commits from egit?
Thanks!
EDIT: I tried a hard reset a few times but it didn't do anything.
EDIT 2: Hard reset does rollback changes indeed, but I want them to completely disappear from the history as if I never made these commits.
RightMouse on your Repository and click on "show in -> history".
You should select the last commit before your last "fetch"...most of the time its the second commit under your current HEAD.
RightMouse on that commit and "reset -> Hard" (will reset all your commits AND local workspace changes to the selected commit).
you should see the up-arrow changing into an down-arrow, meaning that your commits are deleted and that your repository is outdated. Use "fetch" & "rebase" to be up to date.
Note that Egit3.0 in Kepler allows you to hard reset to any treeish expression you want:
But once hard reset, you still need to git push --force after that: if you don't the history of your upstream repo would still list that commit.
You can do a hard reset but be carefull with that !! Here's some more info: Delete commits from a branch in Git