#安裝git 注冊github GitHub建立一個遠端倉庫比如我的名字叫BookStore
#初始化本地倉庫 在本地建立一個與遠端倉庫名字相同的目錄 在此目錄下右鍵點選git bash here 輸入如下指令
git init
#在本地倉庫建立ssh key 一台電腦一個key 此key用于從本地上傳倉庫
ssh-keygen -t rsa -C "[email protected]"
#我自己的倉庫
ssh-keygen -t rsa -C "[email protected]"
#找到剛生成的本地ssh key檔案位置
#我的檔案位置為:C:\Users\DELL\.ssh目錄下 打開id_rsa.pub檔案 複制裡面全部内容
#在github上點選賬戶選擇settings 找到SSH and GPG keys 位置 點選new SSH keys
#網址位置為:https://github.com/settings/ssh/new
#将複制内容加入到key中 title随便寫
#運作測試指令
$ ssh -T [email protected]
The authenticity of host 'github.com (13.229.188.59)' can't be established.
RSA key fingerprint is SHA256:nThbg6kXUpJWGl7E1IGOCspRomTxdCARLviKw6E5SY8.
#初次使用此處需要輸入yes
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added 'github.com,13.229.188.59' (RSA) to the list of known hosts.
#見到這句話說明驗證成功
Hi siriusblack94! You've successfully authenticated, but GitHub does not provide shell access.
#配置送出使用者名和郵箱
git config --global user.name "siriusblack94"
git config --global user.email "[email protected]"
#添加要上傳的遠端倉庫目錄
git remote add origin [email protected]:siriusblack94/BookStore.git
#用git pull從遠端倉庫同步
git pull [email protected]:siriusblack94/BookStore.git
#添加所有檔案到本地倉庫
git add .
#檢視本地與遠端檔案差别
git status
#撤銷本次添加 git reset HEAD XXX XXX為指定某個檔案 不指定取消所有添加
git reset HEAD
#已經修改代碼還未送出復原到上次送出 先檢視節點
git log
commit xxxxxxxxxxxxxxxxxxxxxxxxxx
...
#(回退到 送出的節點 代碼還是原來你修改的)
git reset commit_id
#(回退到commit節點, 代碼也發生了改變,變成上一次的)
git reset –hard commit_id
#恢複某一個檔案
git checkout -- hello.rb
#送出到本地倉庫
git commit -m "BookStore_v1.0_pre-releases"
#還原已經送出的修改
#此次操作之前和之後的commit和history都會保留,并且把這次撤銷作為一次最新的送出
git revert HEAD 撤銷前一次 commit
git revert HEAD^ 撤銷前前一次 commit
git revert commit-id (撤銷指定的版本,撤銷也會作為一次送出進行儲存)
git revert是送出一個新的版本,将需要revert的版本的内容再反向修改回去,版本會遞增,不影響之前送出的内容。
#推送到遠端倉庫
git push -u origin master //git fetch origin master
#倉庫克隆 git clone =git init + git remote + git pull
git clone https://github.com/siriusblack94/BookStore.git
hosts 檔案添加如下dns 解決通路github慢
185.31.16.184 github.global.ssl.fastly.net
idea整合github
idea-> settings->Github->create API Token
idea-> settings->Git->設定git.exe路徑
使用idea首次從github下載下傳到本地倉庫并生成項目
file->new->project from version control->github
或者VSC->checkout from version control->github
使用idea首次将本地項目分享到github(github沒有該倉庫)
VCS->import into version control->share project on github
右擊項目選擇Git進行add commit操作
右擊項目選擇Git->repository->進行操作pull push等操作