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

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.

Related

How to revert a pull request commit on GitHub

I am trying to revert my latest commit on GitHub. All the information I have looked through says that there should be a revert button in the pull request but I do not see it, and cannot find it.
Is there anyway to do this on GitHub? Or could I do it terminal with a few rebase commands?
Assuming this pull request merge is a commit merge (what I would expect), then you may try the following from the Git bash:
git checkout your_branch
git revert <hash of merge commit> -m 1
git push origin your_branch
This solution assumes that you want to revert back to the branch into which the pull request merge was made. If you want to follow the incoming branch, then use -m 2 instead.
To find the SHA-1 hash of the merge commit, you may use git log, and then copy over the hash from the first commit, which should appear at the top.
Note that nuking the merge commit and then doing a force push is generally a bad idea here. The reason it is bad is because your branch is published on GitHub. This means that rewriting the history of that branch could cause problems for anyone besides you who happens to be sharing this branch.
In android studio click version control tab in the bottom. Then click log
Then your all the commits will be visible. Then right click on relvent commit and revert it.
Then commit changes and push again.
Get the hash of the commit in which you want to revert back. Then do:
git checkout 54722c31619b0662b379923d0be4b8f8f1f125c9
The long number you are seeing is the hash of that particular commit in which you want to revert back.
Then force push into the branch you want to revert back.
git push origin <your_branch_name> --force
I hope this helps. Happy coding :)

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.

How do I revert all files to a previous commit using EGit?

I am using EGit 2.2.0.20-1212191850-r with GitHub. All of my local files are committed and pushed. There is only the master branch. I would like to permanently revert all of my files to a previous commit (not HEAD~1). How do I do it?
Here's what I have tried:
I opened the History pane, where I see all past commits.
I right-clicked on the earlier commit and selected Reset > Hard.
I see the old version. I try committing the old version but none of the changed files show up in the Commit Changes window, even if I explicitly add them to the index.
I also tried Checkout in step 2, with the same result.
Eclipse git checkout (aka, revert) is not relevant, since it is just about reverting to HEAD, not an earlier commit.
What I'd really like to do is create a new branch from the earlier commit, but I'll settle for reverting.
If you already pushed the commits, it is generally recommended to revert the commits. The reason for that is that revert will add new commits to the history instead of replacing the history, which makes it possible for other people to just pull instead of having to rebase on the replaced history.
So in the History view, select the newest commit you want to undo, open the context menu and select "Revert". Repeat for the parent commits. When you're done, push the result.
Also note that "git checkout" and "git revert" are different things, "git revert" creates a new commit that undos the changes of a previous commit. "git checkout" on the other hand changes the working directory or current branch to a commit. You may be confused because "svn revert" does what "git checkout" does, not "git revert".

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

How to undo a Git rollback

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.