Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » EGit / JGit » How to discard file modification
How to discard file modification [message #666757] Fri, 22 April 2011 08:07 Go to next message
Hiroki Kondo is currently offline Hiroki KondoFriend
Messages: 47
Registered: July 2009
Member
Hello.

I'd like to discard file modification like "svn revert".
If I use git on CUI, I enter the command "git checkout -- target_of_file"

How to do it on EGit?
Re: How to discard file modification [message #667072 is a reply to message #666757] Tue, 26 April 2011 15:23 Go to previous messageGo to next message
Stefan Lay is currently offline Stefan LayFriend
Messages: 342
Registered: July 2009
Senior Member
"Hiroki Kondo" <kompiro@gmail.com> wrote in message
news:iorci8$mui$1@news.eclipse.org...
> Hello.
>
> I'd like to discard file modification like "svn revert".
> If I use git on CUI, I enter the command "git checkout -- target_of_file"
>
> How to do it on EGit?

Select Team > Replace With > File in Git Index on a file. This does the same
as "git checkout -- target_of_file". What is missing is checking out fioles
from a given commit. Maybe we should additionaly offer a context menu entry
"checkout"?

Please see also http://wiki.eclipse.org/EGit/User_Guide#Reverting_Changes

Stefan
Re: How to discard file modification [message #668183 is a reply to message #666757] Wed, 04 May 2011 11:19 Go to previous messageGo to next message
Stefan Hansel is currently offline Stefan HanselFriend
Messages: 103
Registered: July 2009
Senior Member
As a new user I find the current menu structure for replacements highly unintuitive.

Found this bug-report about it, so hope that other are at least voting for it, to make EGit more user friendly to those of us, that come from other VCS and don't know the git in and outs (i.e. don't know if 'replace with file from git index' is what they really want to achieve their problem at hand.)

https://bugs.eclipse.org/bugs/show_bug.cgi?id=326638
Re: How to discard file modification [message #714883 is a reply to message #668183] Thu, 11 August 2011 16:53 Go to previous messageGo to next message
Dmitry Katsubo is currently offline Dmitry KatsuboFriend
Messages: 14
Registered: November 2010
Junior Member

I have occasionally removed the folder in my workspace (from command line, not from Eclipse).
EGit shows the outgoing changes, but I am not able to revert them (I tried "Replace with" → "HEAD" and "Replace with" → "File in Git Index" in Synchronize view). No reaction. Does it have something to do with https:/bugs.eclipse.org/bugs/show_bug.cgi?id=345002 ?

Is there any way for me to recover / revert?

[Updated on: Thu, 11 August 2011 17:18]

Report message to a moderator

Re: How to discard file modification [message #714943 is a reply to message #714883] Thu, 11 August 2011 20:30 Go to previous messageGo to next message
R Shapiro is currently offline R ShapiroFriend
Messages: 386
Registered: June 2011
Senior Member
Git doesn't track directories (folders), so it doesn't really make sense to run an egit file operation like Replace With on a directory. You need to re checkout the deleted directory to get it back -- that's the command-line Git fix.

Not sure how you'd do it in egit, since it doesn't seem to support 'checkout' at the path level. If you have no other changes you can always use the egit 'reset' operation to reset the repository as a whole. Or you might be able undo the damage from the "Git Staging Area" view.





Re: How to discard file modification [message #715750 is a reply to message #714943] Mon, 15 August 2011 12:00 Go to previous messageGo to next message
R Shapiro is currently offline R ShapiroFriend
Messages: 386
Registered: June 2011
Senior Member
Confirming after some experiments that there doesn't seem to be any way in egit to restore a deleted directory, short of a hard reset of the repository. Note that this situation also applies if you delete the directory from within Eclipse, it's not specific to doing the delete externally.

Is there some way to do this, other than a reset, that I'm not seeing? Obviously a reset is no good if there are other other un-commited changes.

If there is no other way, egit probably needs one. The most general solution would seem to be an optional path in the egit 'checkout' dialog. That would be useful for other situations as well and corresponds closely to the standard command-line Git fix.
Re: How to discard file modification [message #715757 is a reply to message #715750] Mon, 15 August 2011 12:15 Go to previous messageGo to next message
Carsten Reckord is currently offline Carsten ReckordFriend
Messages: 139
Registered: July 2009
Senior Member
On 15.08.2011 14:00, R Shapiro wrote:
> Confirming after some experiments that there doesn't seem to be any way in egit to restore a deleted directory, short of a hard reset of the repository. Note that this situation also applies if you delete the directory from within Eclipse, it's not specific to doing the delete externally.
>
> Is there some way to do this, other than a reset, that I'm not seeing? Obviously a reset is no good if there are other other un-commited changes.
>
> If there is no other way, egit probably needs one. The most general solution would seem to be an optional path in the egit 'checkout' dialog. That would be useful for other situations as well and corresponds closely to the standard command-line Git fix.
>

Two additional ideas spring to mind:

a) Having 'checkout' (and maybe reset soft/mixed) on file entries in the
history view - while this wouldn't hurt, it's still not so nice to have to
hunt for the specific commit that last changed/deleted that file

b) Support browsing the tree for a branch/tag or even specific commits (with
something like svn's REVISIONS or cvs's Dates nodes) in the git repository
and support checkout/reset from there
Re: How to discard file modification [message #715758 is a reply to message #715750] Mon, 15 August 2011 12:25 Go to previous messageGo to next message
R Shapiro is currently offline R ShapiroFriend
Messages: 386
Registered: June 2011
Senior Member
Related note - if you delete a directory, from inside or Eclipse or outside, and then run "Compare With..." on the parent of the deleted directory, comparing against the Index, the HEAD or the current branch, I would expect the "Git Tree Compare" view to list the missing directory and its files. But it doesn't. That sounds like a bug to me.
Re: How to discard file modification [message #715770 is a reply to message #715758] Mon, 15 August 2011 13:20 Go to previous messageGo to next message
R Shapiro is currently offline R ShapiroFriend
Messages: 386
Registered: June 2011
Senior Member
Continuing with these experiments, there's good new and bad news.

Good news: you can generally restore deleted files, and the containing directories, via Restore From Local History. Obviously this depends on your Local History preferences and the specific context in which you try to restore after a delete. Using command-line git is probably easier, especially with Terminal view, and certainly more reliable. But if you don't have command-line git and you act promptly, you can probably restore your deleted files this way.


Bad news: all the previously mentioned issues regarding deleted directories also apply to individual files, even when the containing directory still exists.

I tried deleting a single file to see if Git Tree Compare would show the deletion. It does not. Worse, the parent directory does not have the expected '>' decoration. Thus the Explorer view gives me no indication whatever that I have an un-commited modification. The deletion is listed as a Staged Change in the Git Staging view, but I can't undelete from there. I can un-stage it -- that's as far as I can get using egit. I cannot replace the file from the Index. To undelete without a hard reset I need to depend on on Local History, or resort to command-line git.


Re: How to discard file modification [message #716498 is a reply to message #715770] Wed, 17 August 2011 15:00 Go to previous messageGo to next message
Matthias Sohn is currently offline Matthias SohnFriend
Messages: 1268
Registered: July 2009
Senior Member
Could you file bugs for the problems you discovered ?
Re: How to discard file modification [message #716556 is a reply to message #666757] Wed, 17 August 2011 16:59 Go to previous message
R Shapiro is currently offline R ShapiroFriend
Messages: 386
Registered: June 2011
Senior Member
I filed one bug for all three file deletion issue, since they're closely related to one another: missing entry in Tree Compare, missing decoration on parent directory, and no way to undo short of full reset.

https://bugs.eclipse.org/bugs/show_bug.cgi?id=354982

Previous Topic:.git/info/exclude ?
Next Topic:subtree merge
Goto Forum:
  


Current Time: Thu Apr 18 04:44:00 GMT 2024

Powered by FUDForum. Page generated in 0.02343 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top