天天看点

Xcode连接[email protected]仓库

大家肯定想要将项目连接到git,而在中国,码云中国([email protected])似乎更好用一些,但是其如何配置?如何和Xcode连接?对于小白来说,看官方教程总显得很吃力,于是我整理了下自己的操作步骤。由于Xcode 已经集成了git,建立新项目时钩选使用git,然后按照下面步骤让Xcode和git@osc 建立连接即可。

第一步:成生SSH密钥

打开终端命令工具,输入命令:ssh-keygen -t rsa -C "[email protected]"

这里邮箱地址,换成你自己注册的邮箱地址。

注意ssh-keygen没有空格。屏幕输出:

Generating public/private rsa key pair.

Enter file in which to save the key (/Users/diaosi/.ssh/id_rsa):diaosi

这个文件夹位置也是可以自己设置的

在上方输入生成的密钥文件名,如diaosi,屏幕输出:

Enter passphrase (empty for no passphrase): 输入密码

Enter same passphrase again: 确认密码

Your identification has been saved in diaosi.

Your public key has been saved in diaosi.pub.

The key fingerprint is:

………………

The key's randomart image is:

………………

屏幕提示生成密钥文件成功,保存在/Users/diaosi文件夹下。

第二步:把diaosi.pub中的内容加入git@osc 的SSH密钥中

第三步:添加SSH并连接

输入命令:ssh-add ~/diaosi

~/diaosi 是刚刚生成的密钥文件路径,屏幕输出:

Enter passphrase for /Users/diaosi/diaosi:输入密码

Identity added: /Users/diaosi /diaosi (/Users/diaosi /diaosi)

输入命令ssh -T [email protected],屏幕输出:

The authenticity of host 'git.oschina.net (58.215.179.44)' can't be established.

RSA key fingerprint is 14:b8:b8:0b:c2:b2:5e:ae:f2:21:f8:18:4d:3a:be:fc.

Are you sure you want to continue connecting (yes/no)? yes(输入yes),屏幕输出:

Warning: Permanently added 'git.oschina.net,58.215.179.44' (RSA) to the list of known hosts.

Welcome to Git@OSC , XX!

第四步:设置个人信息

输入命令:

git config –global user.name "……"  (这里写你自己的名字)

git config –global user.email [email protected]

第五步:设置项目

获取git@osc 上的项目路径。

输入命令:cd 项目文件夹

输入命令:git remote add origin https://gitee.com/XXXXXXXX.git  (这里填你在[email protected]上的项目地址)

输入命令:git pull -u origin master //从git@osc 上拉取项目

输入命令:git push -u origin master //提交项目

第六步:Xcode集成

在Xcode中,提交代码到git@osc 前需提交到本地git,否则Xcode会提示你。

在项目或文件上选择文件提交到本地,这里需要注意的是,工程用户数据不要提交到git,因它实时在变化,本地和远程都不要提交,否则Push时提示有文件未提交。

把项目提交到本地:

File->Source Control->Commit

把项目提交到git@osc :

File->Source Control->Push

点击Push按钮即可。

实践发现:当把APP工程文件夹拷贝到一个新电脑时,新版本xcode中,在source control中选择clone… 

将克隆下来的文件夹里的.git license等等隐藏文件,复制到项目文件夹里(覆盖掉原来的),也可以实现连接git。。。

上述参考了官方文档的SS连接方法,感觉比较麻烦。

后来几次我都是直接在终端打开工程文件夹,然后使用命令来操作,感觉更快:

Git 全局设置:

git config --global user.name "林友鑫"

git config --global user.email "[email protected]"

创建 git 仓库:

mkdir TongTong

cd TongTong

git init

touch README.md

git add README.md

git commit -m "first commit"

git remote add origin https://gitee.com/XXXX.git

git push -u origin master

已有项目?

cd existing_git_repo

git remote add origin https://gitee.com/XXXX.git

git push -u origin master