远程私有库

2019-04-10  本文已影响0人  曹来东
image.png
git status
git add .
git status
git commit -m "强行将本地分支和远程分支相关联,产生冲突"
git push
git push --set-upstream origin master
image.png

1.进入主工程所在目录

image.png
CLD:~ caolaidong$ cd /Users/caolaidong/Desktop/远程私有库/remoteLib
CLD:remoteLib caolaidong$ pod lib create RemoteBase
Cloning `https://github.com/CocoaPods/pod-template.git` into `RemoteBase`.
Configuring RemoteBase template.

------------------------------

To get you started we need to ask a few questions, this should only take a minute.

2019-04-11 12:27:56.710 defaults[3763:929842]
The domain/default pair of (org.cocoapods.pod-template, HasRunbefore) does not exist
If this is your first time we recommend running through with the guide:
 - https://guides.cocoapods.org/making/using-pod-lib-create.html
 ( hold cmd and click links to open in a browser. )

 Press return to continue.


What platform do you want to use?? [ iOS / macOS ]
 > iOS

What language do you want to use?? [ Swift / ObjC ]
 > Objc

Would you like to include a demo application with your library? [ Yes / No ]
 > yes

Which testing frameworks will you use? [ Specta / Kiwi / None ]
 > none

Would you like to do view based testing? [ Yes / No ]
 > no

What is your class prefix?
 > LD

Running pod install on your new library.

Analyzing dependencies
Fetching podspec for `RemoteBase` from `../`
Downloading dependencies
Installing RemoteBase (0.1.0)
Generating Pods project
Integrating client project

[!] Please close any current Xcode sessions and use `RemoteBase.xcworkspace` for this project from now on.
Sending stats
Pod installation complete! There is 1 dependency from the Podfile and 1 total pod installed.

 Ace! you're ready to go!
 We will start you off by opening your project in Xcode
  open 'RemoteBase/Example/RemoteBase.xcworkspace'

To learn more about the template see `https://github.com/CocoaPods/pod-template.git`.
To learn more about creating a new pod, see `https://guides.cocoapods.org/making/making-a-cocoapod`.
CLD:remoteLib caolaidong$

2. 将目标pod文件放入如下路径,删除ReplaceMe.m

image.png

进入Example路径,为事例工程添加库依赖

image.png
CLD:remoteLib caolaidong$ cd /Users/caolaidong/Desktop/远程私有库/remoteLib/RemoteBase/Example
CLD:Example caolaidong$ pod install
Analyzing dependencies
Fetching podspec for `RemoteBase` from `../`
Downloading dependencies
Using RemoteBase (0.1.0)
Generating Pods project
Integrating client project
Sending stats
Pod installation complete! There is 1 dependency from the Podfile and 1 total pod installed.
CLD:Example caolaidong$

3.将文件提交到远程仓库

1.进入远程库路径,添加并提交

image.png
CLD:Example caolaidong$ CD /Users/caolaidong/Desktop/远程私有库/remoteLib/RemoteBase
CLD:Example caolaidong$ GIT ADD .
fatal: cannot handle ADD as a builtin
CLD:Example caolaidong$ git add .
CLD:Example caolaidong$ git commit -m "pod库完成"

2.检查spec文件

CLD:RemoteBase caolaidong$ pod lib lint

 -> RemoteBase (0.1.0)
    - NOTE  | xcodebuild:  note: Using new build system
    - NOTE  | [iOS] xcodebuild:  note: Planning build
    - NOTE  | [iOS] xcodebuild:  note: Constructing build description

RemoteBase passed validation.//通过验证
CLD:RemoteBase caolaidong$ pod spec lint

 -> RemoteBase (0.1.0)
    - ERROR | [iOS] unknown: Encountered an unknown error ([!] /usr/bin/git clone https://dev.tencent.com/u/Caolaidong/p/XMGFMSpecs/git/tree/master /var/folders/8l/hqgr6fms2_l3b2r546c87k540000gq/T/d20190411-4772-1q2fnxi --template= --single-branch --depth 1 --branch 0.1.0

Cloning into '/var/folders/8l/hqgr6fms2_l3b2r546c87k540000gq/T/d20190411-4772-1q2fnxi'...
remote: 404 page not found
fatal: repository 'https://dev.tencent.com/u/Caolaidong/p/XMGFMSpecs/git/tree/master/' not found
) during validation.

Analyzed 1 podspec.

[!] The spec did not pass validation, due to 1 error.
CLD:RemoteBase caolaidong$

失败原因:本地验证不会验证 spec文件中的s.source里面有tag标记,我们没有添加tag标记.所以会报错.
s.source = { :git => 'https://dev.tencent.com/u/Caolaidong/p/XMGFMSpecs/git/tree/master', :tag => s.version.to_s }

3.打标签之前,需要远程仓库有代码.需要将代码退送到远程仓库

git push origin master
To https://git.dev.tencent.com/Caolaidong/XMGFMSpecs.git
 ! [rejected]        master -> master (non-fast-forward)
error: failed to push some refs to 'https://git.dev.tencent.com/Caolaidong/XMGFMSpecs.git'
hint: Updates were rejected because the tip of your current branch is behind
hint: its remote counterpart. Integrate the remote changes (e.g.
hint: 'git pull ...') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.
CLD:RemoteBase caolaidong$ git pull origin master
From https://git.dev.tencent.com/Caolaidong/XMGFMSpecs
 * branch            master     -> FETCH_HEAD
fatal: refusing to merge unrelated histories

git pull 失败 ,提示:fatal: refusing to merge unrelated histories

其实这个问题是因为 两个 根本不相干的 git 库, 一个是本地库, 一个是远端库, 然后本地要去推送到远端, 远端觉得这个本地库跟自己不相干, 所以告知无法合并

具体的方法, 一个种方法: 是 从远端库拉下来代码 , 本地要加入的代码放到远端库下载到本地的库, 然后提交上去 , 因为这样的话, 你基于的库就是远端的库, 这是一次update

第二种方法:
使用这个强制的方法

git pull origin master --allow-unrelated-histories
后面加上 --allow-unrelated-histories , 把两段不相干的 分支进行强行合并

git status
git add .
git status
git commit -m "强行将本地分支和远程分支相关联,产生冲突"
git push
git push --set-upstream origin master

git pull origin master --allow-unrelated-histories
From https://git.dev.tencent.com/Caolaidong/XMGFMSpecs
 * branch            master     -> FETCH_HEAD
Auto-merging .gitignore
CONFLICT (add/add): Merge conflict in .gitignore
Automatic merge failed; fix conflicts and then commit the result.
CLD:RemoteBase caolaidong$ git status
On branch master
You have unmerged paths.
  (fix conflicts and run "git commit")
  (use "git merge --abort" to abort the merge)

Unmerged paths:
  (use "git add <file>..." to mark resolution)

    both added:      .gitignore

no changes added to commit (use "git add" and/or "git commit -a")
CLD:RemoteBase caolaidong$ git add .
CLD:RemoteBase caolaidong$ git status
On branch master
All conflicts fixed but you are still merging.
  (use "git commit" to conclude merge)

Changes to be committed:

    modified:   .gitignore

CLD:RemoteBase caolaidong$ git commit -m "强行将本地分支和远程分支相关联,产生冲突"
[master a3a88b9] 强行将本地分支和远程分支相关联,产生冲突
CLD:RemoteBase caolaidong$ git push
fatal: The current branch master has no upstream branch.
To push the current branch and set the remote as upstream, use

    git push --set-upstream origin master

CLD:RemoteBase caolaidong$ git push --set-upstream origin master
Enumerating objects: 93, done.
Counting objects: 100% (93/93), done.
Delta compression using up to 8 threads
Compressing objects: 100% (81/81), done.
Writing objects: 100% (91/91), 28.50 KiB | 2.85 MiB/s, done.
Total 91 (delta 26), reused 0 (delta 0)
To https://git.dev.tencent.com/Caolaidong/XMGFMSpecs.git
   b92b806..a3a88b9  master -> master
Branch 'master' set up to track remote branch 'master' from 'origin'.
CLD:RemoteBase caolaidong$

4打标签

tag值要与PodSpec文件中的version版本相同

CLD:RemoteBase caolaidong$ git tag
CLD:RemoteBase caolaidong$ open .
CLD:RemoteBase caolaidong$ git tag 0.1.0
CLD:RemoteBase caolaidong$ git tag
0.1.0
CLD:RemoteBase caolaidong$ git push --tags
Total 0 (delta 0), reused 0 (delta 0)
To https://git.dev.tencent.com/Caolaidong/XMGFMSpecs.git
 * [new tag]         0.1.0 -> 0.1.0
CLD:RemoteBase caolaidong$

5.检测spec文件配置

pod spec lint

 pod spec lint

 -> RemoteBase (0.1.0)
    - ERROR | [iOS] unknown: Encountered an unknown error ([!] /usr/bin/git clone https://dev.tencent.com/u/Caolaidong/p/XMGFMSpecs/git/tree/master /var/folders/8l/hqgr6fms2_l3b2r546c87k540000gq/T/d20190411-6427-vl66ac --template= --single-branch --depth 1 --branch 0.1.0

Cloning into '/var/folders/8l/hqgr6fms2_l3b2r546c87k540000gq/T/d20190411-6427-vl66ac'...
remote: 404 page not found
fatal: repository 'https://dev.tencent.com/u/Caolaidong/p/XMGFMSpecs/git/tree/master/' not found
) during validation.

Analyzed 1 podspec.

[!] The spec did not pass validation, due to 1 error.
CLD:RemoteBase caolaidong$  pod spec lint

Username for 'https://git.coding.net': 1026190993@qq.com
Password for 'https://1026190993@qq.com@git.coding.net':
 -> RemoteBase (0.1.0)
    - NOTE  | xcodebuild:  note: Using new build system
    - NOTE  | [iOS] xcodebuild:  note: Planning build
    - NOTE  | [iOS] xcodebuild:  note: Constructing build description

Analyzed 1 podspec.

RemoteBase.podspec passed validation.

CLD:RemoteBase caolaidong$

通过验证表示所有配置都正常.只需将spec文件提交到自己私有索引仓库即可.

6.查看当前索引库

pod repo

CLD:RemoteBase caolaidong$ pod repo

master
- Type: git (master)
- URL:  https://github.com/CocoaPods/Specs.git
- Path: /Users/caolaidong/.cocoapods/repos/master

specName
- Type: git (master)
- URL:  https://git.dev.tencent.com/Caolaidong/XMGFMSpecs.git
- Path: /Users/caolaidong/.cocoapods/repos/specName

2 repos
CLD:RemoteBase caolaidong$

7. 将podspec文件提交到远程私有库

pod repo push specName RemoteBase.podspec
本地又两个索引哭一个是官方CocoaPods,另一个是私有的 specName,我们现在是将RemoteBase.podspec提交到我们的私有库specName中.

2.修改Example项目中的.podspec文件

pod repo And pod repo list

CLD:~ caolaidong$ pod repo

master
- Type: git (master)
- URL:  https://github.com/CocoaPods/Specs.git
- Path: /Users/caolaidong/.cocoapods/repos/master

1 repo
CLD:~ caolaidong$ pod repo list

master
- Type: git (master)
- URL:  https://github.com/CocoaPods/Specs.git
- Path: /Users/caolaidong/.cocoapods/repos/master

1 repo
CLD:~ caolaidong$

添加私有仓库

pod repo add specName 项目地址

CLD:~ caolaidong$ pod repo add specName https://git.dev.tencent.com/Caolaidong/XMGFMSpecs.git
Cloning spec repo `specName` from `https://git.dev.tencent.com/Caolaidong/XMGFMSpecs.git`
Username for 'https://git.dev.tencent.com': 1026190993@qq.com
Password for 'https://1026190993@qq.com@git.dev.tencent.com':
CLD:~ caolaidong$

可以看到添加了cocoapods官方以外的specName仓库

image.png

公钥私钥路径

CLD:~ caolaidong$ ssh-keygen//指令
Generating public/private rsa key pair.
Enter file in which to save the key (/Users/caolaidong/.ssh/id_rsa):
/Users/caolaidong/.ssh/id_rsa already exists.//已经存在是否覆盖
Overwrite (y/n)? y
Enter passphrase (empty for no passphrase)://密码
Enter same passphrase again://再次输入密码
Your identification has been saved in /Users/caolaidong/.ssh/id_rsa.
Your public key has been saved in /Users/caolaidong/.ssh/id_rsa.pub.
The key fingerprint is:
SHA256:5zI2/a6cEBM9F/kngJrnNdejMNt+ruoGUva4/j/ZiWU caolaidong@CLD.local
The key's randomart image is:
+---[RSA 2048]----+
|           ...   |
|         .. o.   |
|        .oo .o . |
|        o+.=o +.o|
|        So+.=o.o.|
|       . O.o o E |
|        B = . * .|
|       . B + = + |
|        ..B*=o=. |
+----[SHA256]-----+
CLD:~ caolaidong$
image.png
上一篇 下一篇

猜你喜欢

热点阅读