GIT 配置
- 生成SSH公鑰
cd ~/.ssh
ls
authorized_keys2 id_dsa known_hosts
config id_dsa.pub
關鍵是看有沒有用 something 和 something.pub 來命名的一對檔案,這個 something 通常就是 id_dsa 或 id_rsa。有 .pub 字尾的檔案就是公鑰,另一個檔案則是金鑰。假如沒有這些檔案,或者乾脆連 .ssh 目錄都沒有,可以用 ssh-keygen 來建立
ssh-keygen
Generating public/private rsa key pair.
Enter file in which to save the key (/Users/schacon/.ssh/id_rsa):
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /Users/schacon/.ssh/id_rsa.
Your public key has been saved in /Users/schacon/.ssh/id_rsa.pub.
The key fingerprint is:
43:c5:5b:5f:b1:f1:50:43:ad:20:a6:92:6a:1f:9a:3a schacon@agadorlaptop.loca
它先要求你確認儲存公鑰的位置(.ssh/id_rsa),然後它會讓你重複一個密碼兩次,如果不想在使用公鑰的時候輸入密碼,可以留空。
注:使用git指使用git clone從遠端倉庫拉專案 或git push到遠端倉庫
- 檢視本地公鑰
cd ~/.ssh
cat id_dsa.pub
-----BEGIN OPENSSH PRIVATE KEY-----
b3BlbnNzaC1rZXktdjEAAAAACmFlczI1Ni1jdHIAAAAGYmNyeXB0AAAAGAAAABDHoUcEpu
Z2MauAgKkjPYUaAAAAEAAAAAEAAAEXAAAAB3NzaC1yc2EAAAADAQABAAABAQDewAHiTRhL
llsZcr0B0/lHauTi1r0/qL49RDThYF6apbpLkTqErp8tAveNSrNf/AQYwD+UDaPBRJFYcj
XQ2t+ZbOfII6Nd3PkiStYfZL4BHZ4rRHPMBB1CDFqIhOWSznfUDn3ereM4zdPEXMYGUQF+
j6iI+xJHFqWe/Aqb1G/Ac9tNnKduLAR+7W4l57V+2EhL0EF2WwLWXnLSG5Is0vKMorHsNu
BorS9R8HXEZHr1CaVOuhODASPBIiOP/Kchk2ZuQPiQRzyTGE1yJA0DenmR1soFEuUvZRv1
--------------------------華麗的打碼線--------------------------------
QLGuNupeKC2uoLkZI24wp+NjdadJlK9RiI7mZ1xQK8vfKcZ0ad41Q2qtitRTOQXX+SHwkA
FROpz7hw2zjGpxF7FcNBHMwYqHPknD/6oZrOADiNvzgFHPbtDv7vjCHBXrn/5GaAJLRAZo
nuPq5mxz2lZ/tUcwziGr//E8mCeviHMfN4wjlhBT7PuV+TMr1JRLlh6uPrWY8dqAsexv17
UBfjz/YTJe7mftAXwk7g05KpPJLx0PXKqJyh1/2ooqVp3UqU0RvzjU3kJYVnNPGMXOXTL5
gTKtpHvl1rGLAWTLWL+ONPLMuprMK2XXQAoii5nRN2+3279wYTYh2rVksN0pnTimjOTbr6
JC622Ocz1lKv1RDyBXIae6MlFukVLWlaioTmHeiHfuSpvE+K9Q8YtZIN/om8GshTGZ11KL
KO3vstG69tTaCt7QI/cRmWBUBFxDZtSkkUeozVqOu+QKNumxyN5q0b0c4tOIoE+ERWk1jq
egxjyWdHct1w87hPZ5jDkDmOIADnjS1/mlYeX+tYgbA1Yj+CCk
-----END OPENSSH PRIVATE KEY-----
- 本地全域性設定使用者名稱和郵箱
git config --global user.name "zhangjianhui"
git config --global user.email "309078303@qq.com"
- 檢視使用者名稱
git config user.name
- 檢視郵箱
git config user.email
- 配置遠端倉庫
這裡以alicode為例
登入完成後左側選單選擇 專案->設定->SSH公鑰
將本地ssh公鑰新增進去即可
- 新增遠端倉庫
這裡指定了遠端倉庫別名為 mygit remote add my git://github.com/paulboone/ticgit.git
- 檢視遠端倉庫
git branch -a
* master
my
remotes/origin/HEAD -> origin/master
remotes/origin/master
GIT日常工作流程
日誌及恢復
- 檢視提交(commit)記錄
git log
Author: zjh <309078303@qq.com>
Date: Thu Aug 8 09:06:46 2019 +0800
修復其它訂單資料不正確
commit 4aed74ecfda4f7a1b0aec24cffa47eab48fe43d6
Author: zjh <309078303@qq.com>
Date: Wed Aug 7 11:43:33 2019 +0800
最佳化選擇推薦商品
commit 72757ac561d6710628b895319145a3c0d701f4bc
Author: zjh <309078303@qq.com>
Date: Wed Aug 7 11:42:23 2019 +0800
最佳化選擇推薦商品
commit fd27f006e57cf34d656e8e57a1a3bdea6e93a8cd
Author: zjh <309078303@qq.com>
Date: Sun Aug 4 18:21:07 2019 +0800
試執行版v1.0
-恢復至指定版本
git reset HEARD 72757ac561d6710628b895319145a3c0d701f4bc
本作品採用《CC 協議》,轉載必須註明作者和本文連結