https://blog.csdn.net/dark00800/article/details/54571859
https://code.aliyun.com/help/code-basics/config-ssh-for-windows.md
使用阿里雲code和git管理項目
使用代碼雲托管和git來管理項目可以使多客戶端和多人開發更加高效。通過對比github,bitbucket和國內一些雲托管服務發現阿里雲在項目空間和傳輸速度及穩定性上更能滿足公司開發的要求。本文將介紹關於阿里雲code及git的簡單使用。
一、注冊阿里雲
可以直接使用淘寶賬號登錄,根據官網提示注冊登錄即可。推薦使用綁定了郵箱的淘寶賬號,這樣可以避免一些設置git和ssh時可能遇到的問題。
二、下載和配置git
登錄阿里雲code之后再右上角個人頭像邊上有個幫助按鈕,這里給出了簡單的git教程。
也可以訪問廖雪峰的官方網站學習比較詳盡的git教程
這里給出windows版git官方和網盤的下載地址:
git官方下載
git網盤鏡像
安裝git時選擇要安裝的目錄,一直點擊下一步使用默認配置即可。
安裝完成之后在電腦任意位置點擊鼠標右鍵會出現bash選項,同時可以在開始菜單中找到“Git”->“Git Bash”,打開會出現一個類似命令行的工具,這說明安裝已經成功。
然后開始配置git的user name和email用於身份驗證,打開git bash工具,輸入
git config --global user.name "your name" git config --global user.email "your email"
- 1
- 2
其中your name為淘寶賬號綁定郵箱@前的部分,your email為郵箱賬號,如果注冊時使用的是手機則your name為空即可,這會影響到之后git的使用權限(目前遇到的權限問題,還在驗證中)。例如我們綁定的郵箱為1234567890@qq.com,則配置信息為:
git config --global user.name "1234567890" git config --global user.email "1234567890@qq.com"
- 1
- 2
可以使用如下命令查看已經配置的信息:
git config --global user.name git config --global user.email git config --global --list
- 1
- 2
- 3
三、添加SSH
我們需要在阿里雲code的賬號下添加工作pc對應的ssh已獲得對項目管理的各種權限,在阿里雲code的幫助中有添加ssh的簡單教程。
在git bash中輸入獲取公鑰的指令:
cat ~/.ssh/id_rsa.pub
- 1
如果看到一長串以 ssh-rsa或 ssh-dsa開頭的字符串,說明已經存在本地公鑰(但似乎在創建公鑰時需要對應阿里雲code的賬號,所以我們可以創建一個新的本地公鑰)。
繼續在git bash中輸入:
ssh-keygen -t rsa -C "your account"
- 1
其中your account對應淘寶賬號綁定的郵箱,手機注冊則為空(可在阿里雲code的幫助中查看)。
點擊回車使用默認值,或者可以輸入存放鍵值對和密碼的位置和文件名。結束之后繼續輸入獲取公鑰的指令來獲取公鑰:
將取得的如圖所示的公鑰從ssh開始復制,點擊阿里雲code頁面右上角賬號頭像->個人資料->SSH密鑰->增加SSH密鑰,將復制的內容粘貼入公鑰,並輸入一個標題,然后點擊增加密鑰:
四、新建項目並使用git上傳本地代碼
先在本地創建好Unity項目。
點擊阿里雲code頁面上的新項目,項目路徑填寫項目名字,並輸入項目描述(可選),可見等級選擇私有。點擊創建項目。
在Unity項目根目錄下右擊選擇Git Bash Here,輸入如下指令:
git init
git remote add origin git@code.aliyun.com:account/TestProject.git git add . git commit -am "message" git push -u origin master
- 1
- 2
- 3
- 4
- 5
其中“git@code.aliyun.com:account/TestProject.git“為阿里雲code項目的SSH,在項目界面可以看到。message為本次提交的信息。
出現類似上圖所以消息則推送已成功。項目有修改時只需要在git bush中依次add,commit,和push即可。至此我們就成功在雲端建立了一個項目並將本地的項目推送了上去,之后我們在另一台pc上要編輯項目時只需將項目從雲端pull下來即可,相關教程和git的一些常用指令將在下一章進行講解。
最近阿里雲code進行升級改造,出現一些客戶端支持出問題,大部分原因是客戶端沒有使用原生ssh協議產生。
Windows下使用TortoiseGit的解決方案如下:
- 下載Windows下的git客戶端,git-for-windows
- 打開bash,輸入ssh-keygen.exe -t rsa -C "email" 如果不想輸密碼的話,一路回車會自動生成id_rsa和對應的pub文件
- 打開 阿里雲code的sshKeys頁面,點擊"ADD SSH KEY"添加新公鑰,將剛剛生成的id_rsa.pub文件中的內容復制到Key輸入框中
- 調整TortoiseGit settings中的network選項,將tortoisegitplink.exe改成步驟1中git的安裝目錄(如,user\bin\ssh.exe)。
如果使用idea系列工具,請配置原生的ssh client:
具體配置路徑為:settings-->Version Control-->Git ,SSH executable選擇Native,具體的可以參考git-with-intellij-idea-could-not-read-from-remote-repository
idea在14以上版本,默認將ssh的配置成新的java client
歐陽梁@DESKTOP-2FDU4VJ MINGW64 ~/Desktop
$ git config --global user.name "154757471"歐陽梁@DESKTOP-2FDU4VJ MINGW64 ~/Desktop
$ git config --global user.email "154757471@qq.com"歐陽梁@DESKTOP-2FDU4VJ MINGW64 ~/Desktop
$ git config --global user.name
154757471歐陽梁@DESKTOP-2FDU4VJ MINGW64 ~/Desktop
$ git config --global user.email
154757471@qq.com歐陽梁@DESKTOP-2FDU4VJ MINGW64 ~/Desktop
$ git config --global --list
user.name=154757471
user.email=154757471@qq.com歐陽梁@DESKTOP-2FDU4VJ MINGW64 ~/Desktop
$ cat ~/.ssh/id_rsa.pub
cat: /c/Users/歐陽梁/.ssh/id_rsa.pub: No such file or directory歐陽梁@DESKTOP-2FDU4VJ MINGW64 ~/Desktop
$ ssh-keygen -t rsa -C "154757471@qq.com"
Generating public/private rsa key pair.
Enter file in which to save the key (/c/Users/歐陽梁/.ssh/id_rsa):
Created directory '/c/Users/歐陽梁/.ssh'.
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /c/Users/歐陽梁/.ssh/id_rsa.
Your public key has been saved in /c/Users/歐陽梁/.ssh/id_rsa.pub.
The key fingerprint is:
SHA256:1Rxz2UXXufxTen2MNV1ZsaGcg6v0eU1qnkzt6pa0ymE 154757471@qq.com
The key's randomart image is:
+---[RSA 2048]----+
| o .*%|
| oo++oB|
| ..o=..+|
| . . .++|
| S. . *=|
| . o ..B.*|
| . E.=o+o|
| o B+o |
| o+*.. |
+----[SHA256]-----+歐陽梁@DESKTOP-2FDU4VJ MINGW64 ~/Desktop
$ cat ~/.ssh/id_rsa.pub
ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDqeod1PwDp5i8hNjv1/DpRCGsT327Zv01lbYoiRD+F VJLnJT0UaU/QCTJNoANZWNuE6qLqXIt0bL+A0FCkf4reoSs7S1YLoYJVo/39fvDy32g0GACthB7rSMnW TIa0xaPVAd5bKi9YOpMeJ1gzrU8FDvWUB5LByAejE2rj/AsCjG0svRyxEsIzzxhr4K0PaKG/28Rw2o3Z lzcelMN21y2gR/4e/UgXAjDtND9i3K2S8fUFZpROyj1Uxefhb1OOtCdtdY3g0KO4UkolsU1xX89DzGBm jNgnmecAIZOh/sSkE2qyn0hkCSmmbxJGKjtlZR6sVYbOwt6Cl1ob8ynlVSMn 154757471@qq.com歐陽梁@DESKTOP-2FDU4VJ MINGW64 ~/Desktop
$ clip < ~/.ssh/id_rsa.pub歐陽梁@DESKTOP-2FDU4VJ MINGW64 ~/Desktop
$ touch README.md
git add README.md
git commit -m "add README"
git push -u origin mastergit clone git@code.aliyun.com:youfangTalk/talklocation_android.git
Cloning into 'talklocation_android'...
The authenticity of host 'code.aliyun.com (120.55.150.20)' can't be established.
RSA key fingerprint is SHA256:ZrA2ZqYTVyPbw4zytCSAv74ZMaS2LDH74I7sMPtQIG0.
Are you sure you want to continue connecting (yes/no)? Please type 'yes' or 'no': Please type 'yes' or 'no': Please type 'yes' or 'no': Please type 'yes' or 'no':yes
Please type 'yes' or 'no': no
Host key verification failed.
fatal: Could not read from remote repository.Please make sure you have the correct access rights
and the repository exists.歐陽梁@DESKTOP-2FDU4VJ MINGW64 ~/Desktop
$ git clone git@code.aliyun.com:youfangTalk/talklocation_android.git
Cloning into 'talklocation_android'...
The authenticity of host 'code.aliyun.com (120.55.150.20)' can't be established.
RSA key fingerprint is SHA256:ZrA2ZqYTVyPbw4zytCSAv74ZMaS2LDH74I7sMPtQIG0.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added 'code.aliyun.com,120.55.150.20' (RSA) to the list of known hosts.
remote: Counting objects: 3, done.
remote: Total 3 (delta 0), reused 0 (delta 0)
Receiving objects: 100% (3/3), done.