首先現(xiàn)注冊阿里云賬號 我的是這個(gè) 鏈接
下載和配置git wingit官方下載 git網(wǎng)盤鏡像 提取碼(8es9)
在mac電腦上安裝git有兩種方式:
一是通過安裝homebrew,然后通過homebrew安裝Git,具體方法請參考homebrew的文檔: https://brew.sh/index_zh-cn。
二是通過安裝Xcode軟件,Xcode集成了Git。(當(dāng)然如果用不到Xcode軟件的,建議通過第一種方式)
我這個(gè)就是安裝了Xcode 由于最近有點(diǎn)緊 就現(xiàn)不寫那個(gè)方式了
創(chuàng)建完阿里云賬號
此命令設(shè)置賬號 郵箱 我之前就是想只設(shè)置名字 不設(shè)置那個(gè)郵箱email會(huì)怎樣 之后再說 之后我設(shè)置郵箱后就好了
git config --global user.name "xxx"
git config --global user.email "xxx@xxx.com" 你的郵箱就是你的阿里云郵箱
首先
先進(jìn)入到你想放Git的文件夾 (其實(shí)最好拖入最好)
cd /Users/用戶名/某地方~/
將/Users/用戶名/某地方~/設(shè)置為倉庫
創(chuàng)建新版本庫
git init
會(huì)產(chǎn)生.git目錄 很重要的
之后就是 創(chuàng)建 添加文件 之后上傳
git clone https://code.aliyun.com/路徑/你自己的work.git
cd app-work-你自己的
touch README.md
git add README.md
git commit -m "add README"
git push -u origin master
如果已存在文件夾 阿里上這樣寫的 我沒弄這個(gè)
cd existing_folder
git init
git remote add origin https://code.aliyun.com/路徑/你自己的work.git
git add .
這里旁白下 如果不設(shè)置郵箱的話
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 'xxx@bogon.(none)')
下邊是一些常用的命令
/*
git status查看當(dāng)前狀態(tài)
git add .添加所有修改到暫存區(qū)
git commit -m ‘commit log’ 提交修改到本地repository
git push origin master 將本地的修改同步到遠(yuǎn)程repository
如果修改還沒有被添加到緩存區(qū),可以直接打開git.txt然后把修改刪除也可以使用命令git checkout git.txt
如果已經(jīng)添加到暫存區(qū),可以使用命令git reset HEAD git.txt,從暫存區(qū)刪除,然后git checkout git.txt撤銷修改
如果已經(jīng)提交到repository可以使用git reset --hard HEAD^(git reset --hard version)命令,或者 git revert version前者和后者的區(qū)別:前者會(huì)把本次的commit刪除,后者則是在本次commit的基礎(chǔ)上添加一個(gè)新的commit
git log:查看提交日志
git log --pretty=oneline:查看簡潔的提交日志
git diff:查看當(dāng)前和repository的不同,如果已經(jīng)添加到暫存區(qū)不可用
git reflog:查看所有HEAD的歷史
git show version(git.txt):顯示此版本的變化(某個(gè)文件)
git pull origin chat:更新本地chat分支為最新
git stash :將當(dāng)前修改儲(chǔ)藏
git stash list :儲(chǔ)存列表
git checkout -b chat:創(chuàng)建并切換到chat分支,相當(dāng)于 git branch chat創(chuàng)建chat分支,git checkout chat切換chat分支,兩個(gè)命令
git push origin chat:將此分支添加更新到遠(yuǎn)程
git add -a. git commit -m 'commit log' git push origin chat
*/
之后重新走一下
git config --global user.name "xxx"
git config --global user.email "xxx@xxx.com" 就OK了
可以使用如下命令查看已經(jīng)配置的信息:
git config --global user.name
git config --global user.email
git config --global --list
2.添加SSH
我們需要在阿里云code的賬號下添加工作pc對應(yīng)的ssh已獲得對項(xiàng)目管理的各種權(quán)限,在阿里云code的幫助中有添加ssh的簡單教程。
在git bash中輸入獲取公鑰的指令:
cat ~/.ssh/id_rsa.pub
如果你看到一長串以 ssh-rsa或 ssh-dsa開頭的字符串, 你可以跳過 ssh-keygen的步驟。說明已經(jīng)存在本地公鑰(但似乎在創(chuàng)建公鑰時(shí)需要對應(yīng)阿里云code的賬號,所以我們可以創(chuàng)建一個(gè)新的本地公鑰)。
繼續(xù)在git bash中輸入:
ssh-keygen -t rsa -C "your account"
其中your account對應(yīng)淘寶賬號綁定的郵箱,手機(jī)注冊則為空(可在阿里云code的幫助中查看)。 會(huì)出現(xiàn)
Enter file in which to save the key (/Users/LXS/.ssh/id_rsa): ```
點(diǎn)擊回車使用默認(rèn)值,或者可以輸入存放鍵值對和密碼的位置和文件名。然后,在這里就是設(shè)置存儲(chǔ)地址了.我們直接按回車,會(huì)出現(xiàn)一下兩種情況的一種:
(1)如果正常運(yùn)行的話,會(huì)出現(xiàn)
Enter passphrase (empty for no passphrase):
然后我們直接回車
(2)有的時(shí)候我們可能會(huì)出現(xiàn)
/Users/your username/.ssh/id_rsa already exists.
Overwrite (y/n)?
這說明你已經(jīng)設(shè)置了存儲(chǔ)地址,我們輸入“y”覆蓋
Overwrite (y/n)? y
回車
結(jié)束之后繼續(xù)輸入獲取公鑰的指令來獲取公鑰:
回車后
接著又會(huì)提示你輸入兩次密碼(該密碼是你push文件的時(shí)候要輸入的密碼,而不是github管理者的密碼),
當(dāng)然,你也可以不輸入密碼,直接按回車。那么push的時(shí)候就不需要輸入密碼,直接提交到github上了,
上面的任意兩種情況之后,會(huì)出現(xiàn)如:
> Enter passphrase (empty for no passphrase):
> # Enter same passphrase again:
再次回車,這時(shí)候你會(huì)看見:
Your identification has been saved in /Users/username/.ssh/id_rsa.
Your public key has been saved in /Users/username/.ssh/id_rsa.pub.
The key fingerprint is:
58:42:8b:58:ad:4b:b5:b9:6d:79:bf:8c:f9:e2:2b:ed username
The key's randomart image is:
+--[ RSA 2048]----+
| ... |
+-----------------+
這說明SSH key就已經(jīng)生成了。文件目錄就是:/Users/username/.ssh/id_rsa
我們執(zhí)行cat命令查看文件的內(nèi)容:我執(zhí)行的是這個(gè)
cat ~/.ssh/id_rsa.pub !!
網(wǎng)上有的是:cat c/User/username/.ssh/id_rsa.pub 這個(gè)好像是windows的
這時(shí)候會(huì)看見:
ssh-rsa AAAAB3NzaC1yc2。。。。。。。。。
后面的內(nèi)容省略了
(說明:ssh-rsa 后面的內(nèi)容這就是你的SSH keys,復(fù)制ssh keys的時(shí)候要全部復(fù)制下來,否則會(huì)生成密鑰失敗)
把顯示出來的SSH keys直接添加到github賬戶設(shè)置里邊的SSH keys
添加后,在終端(Terminal)中輸入:
ssh -T 所存儲(chǔ)的平臺(tái)郵箱
例:阿里云 ssh -T git@github.com gitee: ssh -T git@gitee.com
當(dāng)你輸入以上代碼時(shí),可能會(huì)有一段警告代碼,如:
>The authenticity of host 'github.com (207.97.227.239)' can't be established.
># RSA key fingerprint is 16:27:ac:a5:76:28:2d:36:63:1b:56:4d:eb:df:a6:48.
># Are you sure you want to continue connecting (yes/no)?
這是正常的,你輸入 yes 回車既可。如果你創(chuàng)建 SSH key 的時(shí)候設(shè)置了密碼,接下來就會(huì)提示你輸入密碼,如:
Enter passphrase for key '/c/Users/Administrator/.ssh/id_rsa':
當(dāng)然如果你密碼輸錯(cuò)了,會(huì)再要求你輸入,知道對了為止。
注意:輸入密碼時(shí)如果輸錯(cuò)一個(gè)字就會(huì)不正確,使用刪除鍵是無法更正的。
密碼正確后你會(huì)看到下面這段話,如:
Hi username! You've successfully authenticated, but GitHub does not
# provide shell access.
如果用戶名是正確的,你已經(jīng)成功設(shè)置SSH密鑰。如果你看到 “access denied” ,者表示拒絕訪問,那么你就需要使用 https 去訪問,而不是 SSH 。
如果新的一臺(tái)mac會(huì)會(huì)出現(xiàn)權(quán)限問題
Please make sure you have the correct access rights
and the repository exists.
Pushing to git@code.aliyun.com:xxx.git
git@code.aliyun.com: Permission denied (publickey).
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
還有終端(Terminal)安裝xcode tool
出現(xiàn)xcode-select: error: invalid argument '--Software'
xcode commandline tool刪除及重新安裝
sudo rm -rf /Library/Developer/CommandLineTools
xcode-select --install
獲取新的公鑰
cat ~/.ssh/id_rsa.pub
之后copy到 阿里服務(wù)器上
https://code.aliyun.com/profile/keys
權(quán)限問題就會(huì)解決了
如果覺得不錯(cuò)請給小哥哥個(gè)喜歡??! 哈
望大佬大賞!~