5

I have my project on a git repository and so far I'm not finding it terribly useful. I've used git before and think it's great, but this time I'm using a local repo. I figured that there would be some way of restoring files to a previous commit, or even the entire project but I can't find this option?

Is there a way of doing this? Or do I have to create a branch in advance. Because that seems like you have to know in advance that something us going to go wrong.

Also I can't find an option to discard all local changes across my project, effectively reverting to my last commit.

Jonathan.
  • 53,997
  • 54
  • 186
  • 290

3 Answers3

5

I can't find an option to discard all local changes across my project, effectively reverting to my last commit

git reset --hard HEAD

See git reset: that will reset the working tree and the index to what HEAD is currently referring to.
See also the Git book "Undoing in Git - Reset, Checkout and Revert"

For the first part, see git checkout, but beware of detached HEAD.

Community
  • 1
  • 1
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • @Jonathan: right, I am more a console guy ;) Tower is nice also (http://www.git-tower.com/) – VonC Mar 14 '11 at 08:44
  • the consoles great and tower is pretty awesome, but Tower costs quite a bit (compared to the terminal, free obviously, and xcode $5 for IDE as well). I was just hoping that there would be a convenient button in xcode. – Jonathan. Mar 14 '11 at 16:47
  • @Jonathan: I understand and this is perfectly legitimate request. Other Git commands aren't yet fully integrated (as illustrated by this SO question http://stackoverflow.com/questions/5302367/xcode-4-git-integration). So in the meantime... http://stackoverflow.com/questions/456403/can-git-be-integrated-with-xcode/944636#944636 ;) `DTerm` can be a workaround, without having to leave `XCode`. – VonC Mar 14 '11 at 18:05
2

A bit late to this party.

If you can't hack the command line option (it is the best option IMHO) you could try using github:mac to revert / commit / stage code in conjunction with xcode.

It is a very nice and easy to use UI on top of git and it's FREE!!

Don't worry you're not required to push your repo's to github as it will naturally manage local repositories without any fuss.

I regularly use it to rollback projects. Care must be taken when doing this however.

Try not to place 'project.xcworkspace' under revision control. Shutdown Xcode before reverting & discard or stash uncommitted changes.

Judioo
  • 1,083
  • 2
  • 13
  • 20
1

I'm currently in the same boat. It looks like Xcode4 wants us to use the snapshot feature. That has the restore option we want, provided you hit the Create Snapshot when you did your commit. It's conveniently located right under Version Control in the File drop down. The Create Snapshot uses the control + command + s shortcut, which is pretty handy seeing as how I hit command + s for the save hot key often. Or even better yet. Automatically

dhempler
  • 238
  • 2
  • 10
  • I tried creating and restoring from snapshots, but on clicking restore it asked me to open a folder that I wanted to restore, when I just wanted to simply restore the project, selecting a folder just created the correct directory tree but without any restored files. – Jonathan. Mar 23 '11 at 18:47
  • I just found this (http://stackoverflow.com/questions/5302367/xcode-4-git-integration/5364900#5364900) and tried it out via terminal and then loaded my project in Xcode, and it was in the state it should of been at for the commit I selected. It's not 100% from inside Xcode, but it's a way to recover to a previous state with minimal headache. – dhempler Mar 24 '11 at 00:57
  • xcode 4's version control is a total mess. You can not use it for serious source control b/c it's missing alot of critical features. Avoid it completely. – user798719 Apr 16 '13 at 15:58