146

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.

Steve Kuo
  • 61,876
  • 75
  • 195
  • 257
  • 7
    git sucks! It won't show you what you are about to revert before you revert it. Subversion will give you a nice confirmation window with a list of the files you are about to revert. So you can choose which ones you want to revert or cancel on the spot. Shame on the super powerful git. – JohnPristine Feb 13 '13 at 16:01
  • 5
    @JohnPristine The Eclipse git plugin (egit) is the one that would show a confirmation window, rather than git itself. – Brad Cupit Apr 10 '13 at 13:53
  • Right click the file you want to revert, then select "Overwrite". And I agree, Git sucks. – DhafirNz Sep 28 '14 at 23:02
  • In 2016, eGit version 4.5.0 I don't see 'Overwrite'. It seems to now be 'Replace With...' 'HEAD revision' – Ed Randall Oct 17 '16 at 16:31

9 Answers9

279

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

Sergii Rudchenko
  • 5,170
  • 2
  • 28
  • 24
  • 5
    What if the file doesn't exist in the workspace (yet/any more)? – zedoo Sep 04 '14 at 09:59
  • @zedoo If the file doesn't exist open the "Git Staging" view, right click the deleted file in the "Unstaged Changes" list and select "Replace with HEAD Revision" – Vlasta Dolejs Sep 05 '17 at 08:03
45

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.

Community
  • 1
  • 1
simon
  • 734
  • 7
  • 6
  • I just found out the hard way that commit also does the same thing - commits ALL files instead of just the selected file. – Steve Kuo Nov 17 '09 at 23:49
  • Right, but at least you _can_ deselect files in the commit dialog... Btw: I filed a bug for the reset https://bugs.eclipse.org/bugs/show_bug.cgi?id=295423 – simon Nov 18 '09 at 10:16
  • 5
    Git support in Eclipse is really inferior to CVS and SVN because of this! CVS's "Replace with latest from HEAD" functionality is really important to me. – kosoant Jan 13 '10 at 09:19
  • @kosoant Eclipse can do that with Git too. See [this answer](http://stackoverflow.com/a/4104149/152061) – Brad Cupit Aug 12 '14 at 15:48
  • 3
    He asks explicitly about reverting one file, not all of them. – Zofren Sep 11 '14 at 08:49
18

in Eclipse Version: 3.7.0

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

ekeren
  • 3,408
  • 3
  • 35
  • 55
16

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)

zb226
  • 9,586
  • 6
  • 49
  • 79
T A
  • 566
  • 5
  • 13
15

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.

robinst
  • 30,027
  • 10
  • 102
  • 108
  • I wonder why this answer got so less votes. I would prefer to mark this best; would never have figured myself. Thanks @robinst – HarsH Nov 25 '16 at 16:20
8

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

user3812819
  • 81
  • 1
  • 2
4

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

MyItchyChin
  • 13,733
  • 1
  • 24
  • 44
Geddon
  • 1,266
  • 1
  • 11
  • 31
3

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.

robinr
  • 4,376
  • 2
  • 20
  • 18
3

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

adhg
  • 10,437
  • 12
  • 58
  • 94