Git 常用基本指令

  • 170485
  • 0
  • Git
  • 2020-06-15

//從遠端同步檔案下來本機
$ git clone git@11.22.333.123:xxxxxxx.git

//進入資料夾
$ cd xxxx/

//回上一層目錄
cd ..

//回上次工作目錄
cd -

//查看目前位置的所有檔案
$ LS

//查看目前位置的專案
$ ls

//查看所有分支
$ git branch -vva


//轉換分支
$ git checkout (分支名稱xxxx)


//刪除資料夾 (~~)後面接檔案路徑全名

$ rm -rf (~~~~)


//刪除檔案  (~~)後面接檔案路徑全名
$ git rm (~~~~)


//看差異
$ git diff

//開啟某檔
$ vim  xxx.txt

//更改某commit的內容
$ git reset (commit id) 

//清空commit或檔案的動作

$ git checkout -f

$ git clean -fd

$ git checkout (某資料夾)/* 


//先將遠端的檔案拉下來後再把目前完成的commit放上去
$ git pull --rebase 

//回到某commit的狀態
$ git revert (commit id) 


//查看目前狀態 可以看到新增跟刪除等動作
$ git status


//查看commit歷史紀錄
$ git log

 

//離開commit紀錄
$ q


//新增commit
$ git commit
(不管做了甚麼動作最後得加入commit並且pusu才能真的與遠端更新)


//撰寫commit的快捷鍵
選好檔案對準游標位置按d + G (撰寫)表示游標以下的檔案都需要寫上此commit
(技巧:先按d+shift+g就能按出G)

1. i    進入編輯模式(自由打字)
2. Esc   退出編輯模式(回到一般模式)
3. dd     刪除一行(一般模式下)
4. :wq   存檔離開(一般模式下)  要打出:
5. :q!     不存檔直接離開 (一般模式下)  要打出:


//更新至雲端
$ git push


//push推上遠端(分支)
$ git push (分支名稱xxx)


下指令縮寫 

$ git config --global alias.co checkout
$ git config --global alias.br branch
$ git config --global alias.st status
$ git config --global alias.l "log --oneline --graph"
$ git config --global alias.ls 'log --graph --pretty=format:"%h <%an> %ar %s"'

  [alias]
  co = checkout
  br = branch
  st = status
  l = log --oneline --graph
  s = log --graph --pretty=format:"%h <%an> %ar %s"

 

 


資料參考來源:git提示技巧


 


人生美好~別浪費腦容量記程式碼 :- ) 

作者:CYL
出處:http://dotblogs.com.tw/cylcode
資料來源都會特別註明,有興趣都可查詢原出處,本站皆經過整理才分享,如有轉載請顯示出處及作者,感謝。