English 中文(简体)
Eclipse git checkout (aka, revert)
原标题:

Is it possible to do the equivalent of git checkout from within Eclipse using the EGit plugin?

I have a file that s been modified. I want to discards the changes and revert the file back to what s in the source repository. In Subversion this is called revert. In git the equivalent is checkout.

I can t find any menu item under Team that looks like checkout or revert. I m using EGit 0.6.0.

最佳回答

This can be done via the context menu "Replace with/File in Git index" on the file in package view.

问题回答

You can achieve this by doing a (hard) reset. On the project s context menu, select Team > Reset to..., choose "HEAD" and "Hard" as reset type.

Please note that doing this you will lose the changes of ALL files. To revert just a single file see this answer.

in Eclipse Version: 3.7.0

in "Team Synchronizing perspective" --> right click on file/folder in synchronize view --> overwrite

Revert a single file by going to Window > Show View > Other > Git Staging > Unstaged Changes

Select the file(s) you wish to revert. Right click and choose Replace with HEAD revision

Note that this step can t be undone.

(I am using Eclipse Version: 3.7.2 Egit version 2.3.1.201302201838-r)

Another possibility is using the Git Staging view:

  • Open Git Staging view by pressing Ctrl+3 or Command+3 and typing
    staging
  • In case the view does not already show your repository, click on the project or file
  • You should now see the files you modified in the Unstaged Changes section
  • Double-click on the unstaged file
  • You now see a compare view with your version on the left and the version before the changes on the right

Now, to undo only some of the changes in the file, do the following:

  • In the compare view, select one of your changed lines
  • Select the Copy Current Change From Right to Left toolbar item

This will make the left side correspond to the right side for this change. Save the file to finish the undo.

To undo all of your changes:

  • In the staging view, right click on the unstaged file
  • Select Replace With File in Git Index

You can also select more than one unstaged file and then right click.

For reverting, you can right click on the file/directory that you want, then select Replace With -> HEAD version

Open Team Synchronizing. Find the file and right click --> Overwrite.

UPDATE

In Eclipse Luna (4.4.2) Open Team Synchronizing. Find the file and right click --> "Revert..."

The functionality is actually in there, but it may be non-obvious:

  • Make sure quickdiff is enabled with a git revision and the quickdiff baseline is HEAD (this is the default).
  • Open the file you want to revert.
  • Select everything (Ctrl-A)
  • Right-Click in the quickdiff bar
  • Select "Revert selection"
  • Save

btw, revert in git lingo means create a new commit to revert an earlier commit.

To revert your entire file to repository s data:

Click on the folder you wish to do the revision and then go to the GitStaging enter image description here





相关问题
In Eclipse, why doesn t "Show In" appear for non-Java files?

If I have a *java file open, I can right click on the source, scroll down to "Show In (Alt-Shift-W)", and select Navigator. If I have an *xml, *jsp, or pretty much anything besides a Java source ...

Eclipse: Hover broken in debug perspective

Since upgrading Eclipse (Galileo build 20090920-1017), hover in debug no longer displays a variable s value. Instead, hover behaves as if I were in normal Java perspective: alt text http://...

Eclipse smart quotes - like in Textmate

Happy Friday — Does anyone know if eclipse has the notion of smart quotes like Textmate. The way it works is to select some words and quote them by simply hitting the " key? I m a newbie here so be ...

Indentation guide for the eclipse editor

Is there a setting or plugin for eclipse that can show indentation guides in the editor? Something like the Codekana plugin for visual studio (not so fancy is also OK). Important that it works with ...

Adding jar from Eclipse plugin runtime tab

I want to add .jar files for plugin from the Runtime tab of manifest file. When I use the Add... button, I can see only sub-directories of the plugin project. So if I want to add same .jar file to ...

How to copy multiple projects into single folder in eclipse

I have two projects, Project1 and Project2. Now i want to copy this projects into eclipse workspace but i want these projects to be in a single folder like below. Eclipse Workspace -> Project -> ...

Java: Finding out what is using all the memory

I have a java application that runs out of memory, but I have no idea which code is allocating the memory. Is there an application with which I can check this? I use Eclipse.

热门标签