Question

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:

  1. I opened the History pane, where I see all past commits.
  2. I right-clicked on the earlier commit and selected Reset > Hard.
  3. 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.

Was it helpful?

Solution

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".

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top