git config --list
查看git配置
credential.helper=osxkeychain
init.defaultbranch=main
safe.directory=/usr/local/Homebrew/Library/Taps/homebrew/homebrew-core
safe.directory=/usr/local/Homebrew/Library/Taps/homebrew/homebrew-cask
core.excludesfile=/Users/iss730001004790/.gitignore_global
difftool.sourcetree.cmd=opendiff "$LOCAL" "$REMOTE"
difftool.sourcetree.path=
mergetool.sourcetree.cmd=/Applications/Sourcetree.app/Contents/Resources/opendiff-w.sh "$LOCAL" "$REMOTE" -ancestor "$BASE" -merge "$MERGED"
mergetool.sourcetree.trustexitcode=true
commit.template=/Users/iss730001004790/.stCommitMsg
http.sslverify=false
core.repositoryformatversion=0
core.filemode=true
core.bare=false
core.logallrefupdates=true
core.ignorecase=true
core.precomposeunicode=true
cd TestCloudeStorage
git config --local user.name helloyaojun
git config --local user.email cocoyaojun@163.com
4、提交到代码仓。
cd TestCloudeStorage
git config --list
查看git配置
credential.helper=osxkeychain
init.defaultbranch=main
safe.directory=/usr/local/Homebrew/Library/Taps/homebrew/homebrew-core
safe.directory=/usr/local/Homebrew/Library/Taps/homebrew/homebrew-cask
core.excludesfile=/Users/iss730001004790/.gitignore_global
difftool.sourcetree.cmd=opendiff "$LOCAL" "$REMOTE"
difftool.sourcetree.path=
mergetool.sourcetree.cmd=/Applications/Sourcetree.app/Contents/Resources/opendiff-w.sh "$LOCAL" "$REMOTE" -ancestor "$BASE" -merge "$MERGED"
mergetool.sourcetree.trustexitcode=true
commit.template=/Users/iss730001004790/.stCommitMsg
http.sslverify=false
core.repositoryformatversion=0
core.filemode=true
core.bare=false
core.logallrefupdates=true
core.ignorecase=true
core.precomposeunicode=true
cd TestCloudeStorage
git config --local user.name helloyaojun
git config --local user.email cocoyaojun@163.com
查看远程仓,没有输出结果。目前还没有与远程仓库建立连接。
git remote -v
iShot_2023-05-06_10.11.44.png
git remote add origin https://github.com/helloyaojun/TestCloudeStorage.git
git remote -v
//输出结果:
origin https://github.com/helloyaojun/TestCloudeStorage.git (fetch)
origin https://github.com/helloyaojun/TestCloudeStorage.git (push)
执行git pull,自动创建分支。
git pull
//输出结果:
remote: Enumerating objects: 3, done.
remote: Counting objects: 100% (3/3), done.
remote: Total 3 (delta 0), reused 0 (delta 0), pack-reused 0
Unpacking objects: 100% (3/3), 586 bytes | 293.00 KiB/s, done.
From https://github.com/helloyaojun/TestCloudeStorage
* [new branch] main -> origin/main
There is no tracking information for the current branch.
Please specify which branch you want to merge with.
See git-pull(1) for details.
git pull <remote> <branch>
If you wish to set tracking information for this branch you can do so with:
git branch --set-upstream-to=origin/<branch> main
没有指定分支
git pull origin main
From https://github.com/helloyaojun/CloudeStorage
* branch main -> FETCH_HEAD
hint: You have divergent branches and need to specify how to reconcile them.
hint: You can do so by running one of the following commands sometime before
hint: your next pull:
hint:
hint: git config pull.rebase false # merge
hint: git config pull.rebase true # rebase
hint: git config pull.ff only # fast-forward only
hint:
hint: You can replace "git config" with "git config --global" to set a default
hint: preference for all repositories. You can also pass --rebase, --no-rebase,
hint: or --ff-only on the command line to override the configured default per
hint: invocation.
还有警告,重新执行
git config pull.rebase false
git pull origin main
From https://github.com/helloyaojun/CloudeStorage
* branch main -> FETCH_HEAD
fatal: refusing to merge unrelated histories
git pull origin main --allow-unrelated-histories
From https://github.com/helloyaojun/CloudeStorage
* branch main -> FETCH_HEAD
Auto-merging README.md
CONFLICT (add/add): Merge conflict in README.md
Automatic merge failed; fix conflicts and then commit the result.
修改README.md里的冲突后,重新提交
查看分支:
git branch -a
//输出结果
* main
remotes/origin/main
提交代码:
git status
//输出
On branch main
Changes to be committed:
(use "git restore --staged <file>..." to unstage)
new file: CloudeStorageManager.swift
Changes not staged for commit:
(use "git add <file>..." to update what will be committed)
(use "git restore <file>..." to discard changes in working directory)
modified: Example/TestCloudeStorage.xcodeproj/project.pbxproj
Untracked files:
(use "git add <file>..." to include in what will be committed)
Example/Podfile.lock
Example/Pods/
Example/TestCloudeStorage.xcworkspace/
git add .
git commit -m "add CloudeStorageManager"
git push -u origin main
push到远程仓库,报错的解决:
情形一:
git push -u origin main
//输出:
Username for 'https://github.com': helloyaojun
Password for 'https://helloyaojun@github.com':
remote: Support for password authentication was removed on August 13, 2021.
remote: Please see https://docs.github.com/en/get-started/getting-started-with-git/about-remote-repositories#cloning-with-https-urls for information on currently recommended modes of authentication.
fatal: Authentication failed for 'https://github.com/helloyaojun/TestCloudeStorage.git/'
这是因为github原先的密码凭证从2021年8月13日开始就不能用了,必须使用个人访问令牌(personal access token),就是把你的密码替换成token。所以要先去github生成token,将token保存下来。然后执行:
git remote set-url origin https://<你的令牌>@github.com/<你的git用户名>/<要修改的仓库名>.git。
git remote set-url origin https://ghp_agDDF5Gprnwm3w3fYNAMVakWKjjP0D3lGQk@github.com/helloyaojun/TestCloudeStorage.git
git remote -v
origin https://ghp_agDDF5Gprnwm3w3fYNAMVakWKjjP0D3lGQk@github.com/helloyaojun/TestCloudeStorage.git (fetch)
origin https://ghp_agDDF5Gprnwm3w3fYNAMVakWKjjP0D3lGQk@github.com/helloyaojun/TestCloudeStorage.git (push)
情形二:
git push -u origin main
fatal: unable to access 'https://github.com/helloyaojun/TestCloudeStorage.git/': HTTP/2 stream 1 was not closed cleanly before end of the underlying stream
发生这种情况是因为代理是在git中配置的,需要取消代理:
//如果未设置代理
git config --global http.sslVerify false
//如果设置了代理
git config --global --unset http.proxy
git config --global --unset https.proxy
情形三:
git push -u origin main
To https://github.com/helloyaojun/TestCloudeStorage.git
! [rejected] main -> main (non-fast-forward)
error: failed to push some refs to 'https://github.com/helloyaojun/TestCloudeStorage.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.
git config pull.rebase false
git pull origin main
//如果非同源分支需要合并
git pull origin main --allow-unrelated-histories
//修改冲突后再提交
情形四:总是提示输入密码,并且验证错误
Username for 'https://github.com': helloyaojun
Password for 'https://helloyaojun@github.com':
-> TestCloudeStorage (0.1.2)
- WARN | summary: The summary is not meaningful.
- WARN | url: There was a problem validating the URL https://github.com/yaojun/TestCloudeStorage.
- ERROR | [iOS] unknown: Encountered an unknown error ([!] /usr/bin/git clone https://github.com/yaojun/TestCloudeStorage.git /var/folders/pw/qtw0wj9j4cb1kg9v7mgrz9kh0000gn/T/d20230512-24094-10ulkcl --template= --single-branch --depth 1 --branch 0.1.2
Cloning into '/var/folders/pw/qtw0wj9j4cb1kg9v7mgrz9kh0000gn/T/d20230512-24094-10ulkcl'...
remote: Support for password authentication was removed on August 13, 2021.
remote: Please see https://docs.github.com/en/get-started/getting-started-with-git/about-remote-repositories#cloning-with-https-urls for information on currently recommended modes of authentication.
fatal: Authentication failed for 'https://github.com/yaojun/TestCloudeStorage.git/'
) during validation.
git config --global credential.helper store
5、创建podspec文件远程仓库。
iShot_2023-05-06_09.33.12.png
6、校验本地
pod lib lint --allow-warnings
pod spec lint --allow-warnings
git remote set-url origin https://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@github.com/helloyaojun/YJSpecs.git
git branch -M main
注册trunk
pod trunk register 'cocoyaojun@163.com' ‘name'
pod trunk push RCstorage.podspec --allow-warnings