【推荐】2019 Java 开发者跳槽指南.pdf(吐血整理) >>>
背景:osc 合作账号登录,3个月前创建的项目,过程不描述了。前一阵开始用git,安装和使用参考git@osc的帮助文档(传送门:http://www.liaoxuefeng.com/wiki/0013739516305929606dd18361248578c67b8067c8c017b000)。为了方便开发,后续直接clone项目到本地,问题是clone,add,远程仓库等都没问题,只是Push时一直抛出权限问题 " Please make sure you have the correct access rights and the repository exists" 。用一段Github后继续搞起,发现自己当时犯的几个白痴错误一一列举,遇到同样坎的朋友可以参考。
1. 克隆项目到本地, add 和添加到远程仓库,一切都是顺利的
wangs-MacBook-Pro:git-osc wangjiankui$ git clone git@git.oschina.net:wangjiankui/Scavenger.git
Cloning into 'Scavenger'...
remote: Counting objects: 4, done.
remote: Compressing objects: 100% (3/3), done.
remote: Total 4 (delta 0), reused 0 (delta 0)
Receiving objects: 100% (4/4), done.
wangs-MacBook-Pro:git-osc wangjiankui$
wangs-MacBook-Pro:git-osc wangjiankui$ ls
Scavenger
wangs-MacBook-Pro:git-osc wangjiankui$ cd Scavenger/
wangs-MacBook-Pro:Scavenger wangjiankui$ ls
README.md
wangs-MacBook-Pro:Scavenger wangjiankui$ ls
History README.md scavenger.py
wangs-MacBook-Pro:Scavenger wangjiankui$
wangs-MacBook-Pro:Scavenger wangjiankui$ git status
# On branch master
# Untracked files:
# (use "git add <file>..." to include in what will be committed)
#
# History
# scavenger.py
nothing added to commit but untracked files present (use "git add" to track)
wangs-MacBook-Pro:Scavenger wangjiankui$
wangs-MacBook-Pro:Scavenger wangjiankui$ git add History
wangs-MacBook-Pro:Scavenger wangjiankui$ git add scavenger.py
wangs-MacBook-Pro:Scavenger wangjiankui$ git status
# On branch master
# Changes to be committed:
# (use "git reset HEAD <file>..." to unstage)
#
# new file: History
# new file: scavenger.py
#
wangs-MacBook-Pro:Scavenger wangjiankui$ git remote
origin
wangs-MacBook-Pro:Scavenger wangjiankui$ git push origin master
Access denied.
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.
错误一:将publich key错误添加到项目的部署公钥中,一定注意是加到自己账号的公钥中,地址:http://git.oschina.net/keys。
错误二:SSH配置有问题,参考了Jackin的文档,后面的添加key到/etc/.ssh/ssh_config一步,因为我本身机器中的文件没有配置,所以没有按照文档做。
wangs-MacBook-Pro:Scavenger wangjiankui$ ssh-add -l
2048 2f:56:43:c3:7d:72:6a:98:d8:aa:77:92:c5:65:10:59 /Users/wangjiankui/.ssh/github_rsa (RSA)
2048 b6:2f:c7:f5:94:57:1f:06:d1:ca:9a:29:f4:e7:b6:26 /Users/wangjiankui/.ssh/id_rsa (RSA)
wangs-MacBook-Pro:Scavenger wangjiankui$
wangs-MacBook-Pro:Scavenger wangjiankui$ ssh-add /Users/wangjiankui/.ssh/id_rsa_osc
Identity added: /Users/wangjiankui/.ssh/id_rsa_osc (/Users/wangjiankui/.ssh/id_rsa_osc)
wangs-MacBook-Pro:Scavenger wangjiankui$ ssh-add -l
2048 2f:56:43:c3:7d:72:6a:98:d8:aa:77:92:c5:65:10:59 /Users/wangjiankui/.ssh/github_rsa (RSA)
2048 b6:2f:c7:f5:94:57:1f:06:d1:ca:9a:29:f4:e7:b6:26 /Users/wangjiankui/.ssh/id_rsa (RSA)
2048 0c:4b:19:14:b8:31:fc:e8:22:13:26:2c:d3:fb:af:5f /Users/wangjiankui/.ssh/id_rsa_osc (RSA)
wangs-MacBook-Pro:Scavenger wangjiankui$
wangs-MacBook-Pro:Scavenger wangjiankui$ ssh -T git@git.oschina.net
Welcome to Git@OSC , 王建奎Jerrick!
wangs-MacBook-Pro:Scavenger wangjiankui$
wangs-MacBook-Pro:Scavenger wangjiankui$ git push -u origin master
Counting objects: 5, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (4/4), done.
Writing objects: 100% (4/4), 2.55 KiB, done.
Total 4 (delta 0), reused 0 (delta 0)
To git@git.oschina.net:wangjiankui/Scavenger.git
a12daef..fa394ab master -> master
Branch master set up to track remote branch master from origin.
这样就成功了,开会去了,先写这么多。
新的问题:commit时提示:fatal: unable to auto-detect email address
vi ~/.ssh/
github_rsa github_rsa.pub id_rsa id_rsa.pub known_hosts
ssh-add -l
2048 bd:4d:21:c6:6f:ff:8e:86:f6:af:e8:8c:d4:97:6c:90 /Users/wangjiankui/.ssh/id_rsa (RSA)
2048 48:36:b2:ac:76:ca:c8:87:b5:18:68:79:8c:7c:b4:84 /Users/wangjiankui/.ssh/github_rsa (RSA)
wangs-MacBook-Pro:Scavenger wangjiankui$ vi ~/.ssh/known_hosts ##删除git@oschina 的记录
wangs-MacBook-Pro:Scavenger wangjiankui$ ssh -T git@git.oschina.net
The authenticity of host 'git.oschina.net (112.124.6.106)' can't be established.
RSA key fingerprint is e3:ee:82:78:fb:c0:ca:24:65:69:ba:bc:47:24:6f:d4.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added 'git.oschina.net,112.124.6.106' (RSA) to the list of known hosts.
Welcome to Git@OSC, 王建奎Jerrick!
wangs-MacBook-Pro:Scavenger wangjiankui$ ssh -T git@git.oschina.netWelcome to Git@OSC, 王建奎Jerrick!
wangs-MacBook-Pro:Scavenger wangjiankui$
wangs-MacBook-Pro:Scavenger wangjiankui$ git commit common/toolutil.py
*** Please tell me who you are.
Run
git config --global user.email "you@example.com"
git config --global user.name "Your Name"
to set your account's default identity.
Omit --global to set the identity only in this repository.
fatal: unable to auto-detect email address (got 'wangjiankui@localhost.(none)')
wangs-MacBook-Pro:Scavenger wangjiankui$
wangs-MacBook-Pro:Scavenger wangjiankui$ Omit --global
-bash: Omit: command not found
wangs-MacBook-Pro:Scavenger wangjiankui$ git config --global user.email "zzzzzz@126.com"
wangs-MacBook-Pro:Scavenger wangjiankui$ git config --global user.name "王建奎Jerrick"
wangs-MacBook-Pro:Scavenger wangjiankui$
wangs-MacBook-Pro:Scavenger wangjiankui$ git commit common/toolutil.py
Aborting commit due to empty commit message.
wangs-MacBook-Pro:Scavenger wangjiankui$ git commit common/toolutil.py -m '小时抓取'
[master eb6918f] 小时抓取
1 file changed, 3 insertions(+)
wangs-MacBook-Pro:Scavenger wangjiankui$
wangs-MacBook-Pro:Scavenger wangjiankui$ git push -u origin master
Counting objects: 7, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (4/4), done.
Writing objects: 100% (4/4), 399 bytes, done.
Total 4 (delta 3), reused 0 (delta 0)
To git@git.oschina.net:wangjiankui/Scavenger.git
20a8fd0..eb6918f master -> master
Branch master set up to track remote branch master from origin.
来源:oschina
链接:https://my.oschina.net/u/146658/blog/188002