2018年10月8日 星期一

對於git一些常用指令紀錄



git reset —mixed 默認值,回歸某標籤,標籤以後檔案依舊會留存在Working directory,但更改內容不在staged Area裡面,要從新add and commit

git reset —hard  回歸某標籤,標籤以後檔案不會留存在Working directory,直接拋棄某標籤以後的修改。

git reset —soft 回歸某標籤,介於mixedhard間操作,標籤以後檔案依舊會留存在Working directory,更改內容也在staged Area裡面,不用從新add,但要commit


git reset [ae3034d] 指定標籤回歸,檔案依舊會留存在Working directory,但不在staged Area裡面,要從新add and commit

git reset [current~2] 當前往前數兩個回歸,檔案依舊會留存在Working directory,但不在staged Area裡面,要從新add and commit


git commit —amend  不會產生新的commit,會依照之前的commit來添加檔案內容,和可修改commit message內容
more fileName 得知檔案內容

git log —oneline 打印 history of commit ,並一個commit 印出一行資訊

git checkout -b [branchName] 創建一個分支,並轉換過去

git branch [branchName] 創建一個分支,不會轉換過去

git branch -a 看全部的分支

git checkout [branchName] 轉換分支

git branch 得知此分支名稱

git branch -D [branchName]刪除某分支

more [fileName] 印出檔案內容

more .git/config 觀看此專案的資訊

git remote -v 顯示遠端服務器的名稱

git diff [branchName] 用此分支和其他分支比較檔案差別。

git merge [branchName] 結合某分支

git fetch [origin] [branchName]獲取遠端服務器某分支的版本 

git merge FETCH_HEAD 本地使用fetch之後,用這個指令才能同步

git pull  直接一次性解決fetch and merge的問題,但通常不推薦,通常一步一步來,先fetch然後diff來了解是否merge

origin 代表服務器的名稱

git [instruction] -h 查看某指令使用方法

git push origin —delete [branchName]刪除遠端的分支

git branch -m [branchName] 更改分支名稱

git tag -l 目前標籤名稱列

git fetch -t 抓取遠端的標籤

git push —tag 本地標籤傳入遠端

git tag -d [tagName] 刪除某本地標籤

git push origin :refs/tags/[tagName] 刪除遠端標籤

git remote add [remoteName] [remoteLink] 增加一個遠端

產生push遠端不需要一直輸入帳號密碼

step1:ssh-keygen 生成public and private key in /root/.ssh/

step2:GitHub->settings->SSH and GPG keys 把本地電腦id_rsa_pub複製貼過去

step3:vim .git/config 如果使用後還是需要帳號密碼,代表我們走的是https,要更改成ssh(github上複製過來)

額外補充:ssh-copy-id -i /root/.ssh/id_rsa.pub [account]@[IP] 如果對方是linux電腦,可以使用此方法傳遞public key


平行別人專案步驟

step1:git remote add upstream GitHub@IP

step2:git fetch upstream

step3:git merge upstream/master

step4:git push origin master


沒有留言:

張貼留言