3

I'm using EGit with Eclipse Indigo SR 2 Build 20120216-1857.

Almost everything works well, except the Replace With -> Commit... function. In fact it works, but doesn't restore the project exactly like it was because it left the new files that I added since.

It looks like it does a kind of a mix between current HEAD and the commit I choose to restore. What I really want is to replace the content of my project with a previous commit like it does when you switch between branches.

Is there any solution ? And does anyone knows if the lastest version of Eclipse provide a fully working version of EGit ?

Or am I misunderstanding this feature ?

Mickäel A.
  • 9,012
  • 5
  • 54
  • 71
  • You want to restore a previous state of the project? Permanently or temporarily? Or just a single file? – tewe Jan 31 '13 at 22:28
  • I just want to restore the content of my project from what it was in a previous commit. No matter I try on the whole project or on the **src** folder it doesn't work, or maybe I don't understand this feature, but *Replace With...* is self explanatory. – Mickäel A. Feb 01 '13 at 06:19

3 Answers3

3

The "Replace with" I know in Egit is about git checkout (and not git revert, as robinst comments below).
And checkout is not the same than reset.

What I really want is to replace the content of my project with a previous commit like it does when you switch between branches.

That would be closer to the feature "Reset".
Selecting the "hard reset" would remove any private file and completely restore both the index and the working tree to the selected commit.

reset in Egit

(from "How to delete commits with Egit?")

hard - the HEAD points now to the new commit, the index and the working tree are updated.

You also can see it in this tutorial:

reset in Egit bis

Community
  • 1
  • 1
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • It may be what I am looking for, but when I choose *Reset* I can only choose a branch, a ref or a tag but not a commit. Am I forced to tag the commit which I want to go to or is there another way ? – Mickäel A. Feb 01 '13 at 09:14
  • @miNde in that case, set a tag on the commit you want to reset to ;) – VonC Feb 01 '13 at 09:15
  • Ok thx it worked, but I got a problem using *Reset* because it made the master branch to delete all the commits made after the one I choose to reset from. But I don't want that, I just want to be able to return to a previous commit to see the whole code and eventually run it. Finally I could have it to work by using *Checkout* on the commit. – Mickäel A. Feb 01 '13 at 09:24
  • *Replace with* does not do a `git revert`, it corresponds to a `git checkout ref -- paths`. Revert is also available in EGit, but that creates a new commit with the changes reversed. Replace with changes the working directory. – robinst Feb 01 '13 at 11:27
  • @robinst good point. I have edited my answer to reflect your comment. – VonC Feb 01 '13 at 13:59
3

@VonC pointed me towards one solution but that's not really what I want.

I tried the Reset command but first, I had to tag the commit to be able to choose it. Then it changes the whole master branch and canceled the next commits. In fact I don't want to change any branch or to delete any commits, I just want to be able to return to a previous one to see the whole code and eventually run it.

Finally I could have it to work using Checkout on the commit. To see all the commits : Right click on your project -> Show In -> History

It will not modify any branch your were working on but just replace the content of your project by the one the commit has saved.

Mickäel A.
  • 9,012
  • 5
  • 54
  • 71
0

Newly created files are not in git index (untracked) unless you add them into. Since you are reverting your workspace back to a commit, only your tracked files (added to git index) will be modified. Newly created files are not touched.

If you want to delete your untracked files:

git clean -f -d will do it.

ogzd
  • 5,532
  • 2
  • 26
  • 27
  • When I said "new files" I was talking about files that have already been committed at least 1 time, not untracked files. – Mickäel A. Feb 01 '13 at 06:22