Run older commits of project in Xcode - xcode

I am using Xcode with source control. Is it possible to select an older commit of the actual project (just like in the Revisions tab) and run it without the need of git cloning?

It's relatively straightforward using the command line.
If the commit you want to target is named 0ad5a7a7, then you can create a new branch via this:
git checkout -b old-project-state 0ad5a7a7
After creating that branch, you can change to it via Xcode's "Switch To Branch" menu item and you can then build it.

Follow this answer
Then additionally you may need to run
pod install
or
bundle exec pod install
based on your project dependency.

Related

Is there a way to avoid running `pod install` manually and not commiting Pods directory at the same time?

On my current project I am asked not to commit my Pods directory, and at the same time, guys want me to 'add some script' to XCode build phases which will run 'pod install' automatically before each installation if needed.
The goal is not to run pod install manually in terminal after you clone the repo.
I have spend a day trying to solve this and I've found a couple of references with no much detail:
iOS using pod install as Pre-action run script for building the project
CocoaPods version control, must use pod install when cloning repo
I've also found out that for CI the same problem is solved by setting actions in .yml file:
Travis-CI is unable to open file
Do you know what this kind of script could look like?
Maybe it would be best if this could be separated in 2 different questions.
But now that we are here already, to avoid the pods directory on your repository, add this line to your .gitignore file:
Pods/
For your second question regarding running pod install. On Xcode:
Click your scheme icon on the top left and select "Edit Scheme..."
Alternatively select from the menu "Product -> Scheme -> Edit scheme..."
In Scheme Window expand "Build"
Select "Pre-actions"
Click on + and choose "New Run Script Action"
Select to provide the build settings from your target
Add the script:
cd ${PROJECT_DIR}
test -e Pods || pod install && sleep 30
Description of the script:
Changes directory to the project's main folder
Checks if there is a file or folder named Pods, if not runs pod install and waits 30 seconds (before continue with the build). You might want to adjust to wait more or less, according to how long you need to wait for the pods to be downloaded.

How can I fix error: pathspec 'git-practice-project/git-practice-project' did not match any file(s) known to git

I've created a project to practice using Git with Xcode and GitHub. After a lot of work, I've got the repositories created both locally and remotely. I just tried to make a commit and got this error:
Here's what I'm trying to commit:
The last things I did before I got this error were:
I added a .gitignore file using the GitHub Swift template in order to remove the .xcscheme file from the cache
from the Terminal, I ran 'git rm --cache'
I created the test_file and then tried to Commit
But I can see the folder in the finder:
I looked around SO a lot and found many questions about git commit problem but what I found had mostly to do with diacritics and other issues that aren't the same as mine.
Did the 'git rm --cache' lead to this situation? What can/should I do to safely correct this problem?
Thanks
Update: Seems I really got myself into pickle. I've got nested 'git-practice-project' directories several levels deep:
I've started at the deepest directory, did an ls, and a git status, the backed myself up to the top doing the same thing at each level. It looks like only the two highest directories have uncommitted changes and the project.pbxproj file exists in both of them.
I don't use Xcode's SCM features so I am not sure why Xcode is confused here. But it looks like the files under git-practice-project/git-practice-project aren't known to git yet. You need to add the directory to git. On the command line from the project's root directory you could try:
git status
That should list your files that have been modified, deleted, and that aren't part of the git repo yet.
Add the directory and its contents:
git add git-practice-project
Once you have done that, you should be good to go to use the SCM tools in Xcode again.
Update: In Xcode, you can select the file that is marked with the ? and then go to the Source Control menu and select Add Selected Files.
Ran into this with Xcode 10, with newly added files. You first need to add the new files to the repository. Simply select the file in the navigator on the left, right-click, then Source Control in the pop-up, and select "Add Selected Files". After this the commit will work.

The working copy <Project name> failed to commit files. - The repository has an uncompleted operation

I've just updated my Xcode from 6 to 7 (and code from Swift 1.2 to Swift 2.0) and try to create new branch in Xcode. After that I can't push my code to Bitbucket.
Is there a way how can I delete repository from directory and setup Bitbucket again and maybe push to another (a new one) repository? Fix of this problem will be great, but I will be satisfied even with move to another repository.
I had this error in xcode 7.1 on a year old project that was working fine. In my case I have a project with the default local repository created by xcode. For anyone who is not going to re-install and re-setup. It is possible to find out what the dangling command is and fix it from command line.
To find the dangling command Open Terminal from the project directory:
xcrun git status
In my case the status returned:
On branch master
You are currently rebasing.
(all conflicts fixed: run "git rebase --continue")
To fix the problem I used:
xcrun git rebase --skip
In my case I ran git status which revealed that You are currently bisecting. (I was doing a bisect and must had forgotten to reset). I did a git bisect reset and attached the head to my latest commit and it was all fine afterwards.
When I am merging from currentBranchA into branchB, I got conflicts,I didn't want to solve the conflicts immediately and quit the merging process. But when I try to merge again, the Xcode shows "The working copy is currently in the middle of another operation..."
I opened the terminal ,cd to the project directory, and check the git status:
git status
it shows:
On branch currentBranchA
Your branch is up to date with 'origin/currentBranchA'.
All conflicts fixed but you are still merging.
(use "git commit" to conclude merge)
Just do it as it says. Continue to input
git commit and click Ctrl + C to close the commit message window.
The problem will be zero.
The problem was with installation of GitHub. I had a master repository. After reinstall and resetup everything works like before.
EDIT: For anyone who has a problem with Xcode and GIT I have a best advice. Don't use it. Use for example Source Tree
When you start developing for a living, you are gonna have to use more reliable solution for GIT. Imagine you have 70 branches. Using Source Tree you can easily solve conflicts and other things about working in team. Xcode GIT solution is not reliable and you are gonna be only frustrated.

Why doesn't source control check in my CocoaPods?

I have a few Cocoapods installed for my project. For one particular pod, KVNProgress, Xcode doesn't commit it to GitHub. Each time I check my project out I get 'can't find KVNProgress.h' blah blah...
So I run 'pod update' from terminal and immediately all is fixed.
After running 'pod update', I check my project navigator and there are no 'A' or 'M' or anything else for that matter indicated a new or modified file. Therefor nothing to commit.
Any ideas how to fix this so I don't have to update the pods each time I check out the project?
You should use the Terminal to figure out if it's an Xcode problem or a git problem.
Run git status --ignored in the project directory. If the Pods directory is shown in the Ignored files section you have to remove Pods from your .gitignore file.
If the files appear in the untracked files section Xcode messed up the git status.
You can use git add . to add all untracked files.
As a side note, I would recommend to use a dedicated git client like SourceTree, GitHub Mac, or Tower instead of Xcode. Xcodes git implementation is not the best (feature wise) and it's a bit buggy.

Pull specific revision from master branch?

Im very new to Git and what I want to do with git within xcode is pull an older revision of my master (not commandline). Is this possible? I've looked in repositories under the organizer and i see all my commits there but i cant seem to load in one of them.
You can't go back to an earlier version of a repository from Xcode in Xcode 4. Older versions of Xcode allow you to go back to an earlier version of a repository, but older versions of Xcode lack git support.
I think that if you have cloned/pushed your repo all the stuff you need is on your local drive.
If you want to see how code looks in specific commit, do
git checkout branch_name
or
git checkout 14646bf1a76d08cbda99317c4faa8de0072d6975
where branch_name can be alias for checksum used by git, (like master or origin/master), if you want to list your branch checksums you can do that by
git log
or if you want it in GUI use qgit gitg or my favourite tig, or whatever you'll find to list your commits

Resources