4

Hey, I'm now using Xcode 4 for a few weeks. It's just great to come from Xcode 3 and see all the new features. I like the git integration. But I have the one and other problem with that. The newest project I started with a local git repository. That all works fine and I did multiple commits. I want to get an older version of my project. So I try to use Pull. But as soon as I click that button, I get the following message:

The operation could not be performed because access to the repository "/Users/***/Desktop/TestClone" was denied.

Check your name and password and try again.

The problem is, I didn't define anywhere a name and a password. How can I get a copy of a state in my project? The checkout button is always grayed out so I can't click that one.

Any help would be appreciated. :-D

Sandro Meier
  • 3,071
  • 2
  • 32
  • 47

3 Answers3

14

You should not use the 'pull...' command for "going back to" (checking out) an older version of your code.

The 'pull' and 'push' commands are used for synchronizing your local repository with an "origin" remote repository. This feature is normally used when you 'clone' an original remote repository in order to coordinate your changes with other programmers.

If you created your project from scratch, you won't have any remote repository to push to or pull from.

Back to the original question, as far as I know, Xcode 4 won't let you to checkout older commits within the user interface, unless you created a new branch for that commit. Nevertheless, you can do it from the command line. For that, use the following command from your project folder

$ git log --format=oneline

to get the hash code of the commit you want to go to, and then use:

$ git checkout desired-hash-code

to checkout that particular version. Once there, you can make tests, changes, and possibly create a new branch. If you do a commit without creating a new branch, you will lose the newer commits in your current branch. If you want to go back to the newest commit after having performed some tests on your older version use:

$ git checkout master

note again that this won't work if you do a new commit from your old code version without creating a new branch, because newer commits in the current branch get dereferenced.

If you are new to Git, I would read any of these documents:

I would also like to highlight these two:

Cheers.

Ricardo Sanchez-Saez
  • 9,466
  • 8
  • 53
  • 92
  • 5
    By the way, you can use all git commands without closing your project in Xcode 4, as it will happily reload the changed files. – Ricardo Sanchez-Saez Mar 19 '11 at 21:12
  • Thank you very much for the explanation. It really helped me. I'll try it out. And yes I'm new to git. I used subversions once before... I'll read these documents. :-D – Sandro Meier Mar 23 '11 at 15:59
  • well that comment didn't come out... try again. here is a list i had to go through to get my old commit: cd /Users/yourName/Desktop/yourApp/.git then since i could only find git in older developer folders /Developer\ 4.1/usr/bin/git log --format=oneline so now you see the hash... then /Developer\ 4.1/usr/bin/git reset 505bd4eb95ddedaf0a165b706d8ec556fc728574 (or what ever your hash is) – hokkuk Mar 19 '12 at 01:00
  • @hokkuk: You can make 'git' available at the system level by installing the 'Command Line Tools' package in Xcode -> Preferences -> Downloads -> Components. – Ricardo Sanchez-Saez Feb 08 '13 at 15:29
1

If you have already created branches, you can revert to a branch point using the Repositories tab of the Organizer in Xcode. Here's how:

  1. From Xcode, open the organizer by going to Window menu->Organizer, or pressing the keyboard shortcut, Shift+Cmd+2
  2. Click the Repositories view on the top toolbar
  3. In the right nav pane, click on the working directory (it will have a blue folder icon) for the appropriate project
  4. At the bottom left of the organizer window, click on the Switch Branches button.
  5. A pop-up will appear allowing you to select the branch to use; select the desired branch, click OK, and Xcode will sync all the files to that branch.

Also, see https://developer.apple.com/library/mac/#recipes/xcode_help-repositories_organizer/articles/SwitchingBranches.html for a video guide

rodamn
  • 2,191
  • 19
  • 24
0

I think the problem is you are updating the project file with the project open. You may have to close the project, or quit Xcode, to check out an older version of the project using the command line or DTerm, not from within Xcode.

Mark
  • 6,108
  • 3
  • 34
  • 49
  • Thank you for your answer. I'm not really used to git. It's my first try to use it. Could you tell me how the check out a project with the command line? That would be great. :-D – Sandro Meier Mar 14 '11 at 20:28