Cancel undo commit VSCode - github

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.

Related

Git Rebase Interactive

I'm trying to delete old github commits with the interactive rebase, but I don't know how to actually save the changes I've made and push them onto my repository. I haven't found anywhere that actually explains how to exit the interactive rebase, and keep your changes. Help?
You just need to finish the rebase instructions in your editor.
Exit your editor, and it should apply your changes.
If there are any conflicts while rebasing, you'll have to fix them, stage your changes and use git rebase --continue.
That's it. The rebase will finish itself.
Once you're done, you'll have to force push to overwrite the remote state of your branch.

Git reset hard and going back

From git gui, I used gitk to git reset -hard to a few commits before my current one, as I needed to test if everything was working before the changes.
Since I even had a few uncommitted changes, I git stash in order to save them and being able to reapply them once going back to my last commit.
The problem is that gitk is not showing the top of my commit tree any more (the top commit is the current one and I don't see any commit above it)
It was sometimes since last time I used git, but I thought I can use git reset -hard to bring the current code to a previous version, and then git reset -hard to the old version.
How can I retrieve all the commit between the old HEAD and the revision I git reset -hard to?
Please tell me there is some kind of way.
I'm using Eclipse as development tool (in case I'll need to use it's cache)
What you did could work if you had first make a new branch, before the first git reset --hard.
Because git reset moved your current branch back, and those commits are no longer referenced by any branch (and not visible anymore)
You need to fallback to the command line, and try a:
git reset --hard ORIG_HEAD
# or
git reset --hard HEAD#{1}
ORIG_HEAD or HEAD#{1} should have the SHA1 you were before the first reset.
If not, git reflog can help (that is what HEAD#{1} should be listed in).
Not, as alluding to in "ORIG_HEAD and FETCH_HEAD from history view in Eclipse", you should be able to see ORIG_HEAD in the "History view" of Eclipse.

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

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.