GitHub 常用指令

2018, Nov 25    

將檔案push至網站

  • 初始化
$ git init
  • 新增一個說明檔 或指定資料夾
$ git add README.md
  • 新增所有檔案
$ git add .
  • commit 編輯說明
$ git commit -m "first commit"
  • 查看當前狀態 ※步驟可省略
$ git status
  • 指定 要上傳到哪個專案
$ git remote add origin https://github.com/dyeat/dyeat.github.io.git
  • 將檔案推上去 推至哪個來源
$ git push -u origin master

※2018-12-1 Update

取得原作專案最新版

$ git pull

查詢遠端分支

$ git remote -v
origin  https://github.com/dyeat/dyeat.github.io (fetch)
origin  https://github.com/dyeat/dyeat.github.io (push)

選擇抓取的遠端分支

$ git fetch origin

※2018/12/06 update

設置 上傳使用者

$ git config --global user.email "you@example.com"
$ git config --global user.name "Your Name"

查看 配置

$ git config --list

※2018/12/08 update

刪除檔案

$ git rm test.txt

※2018/12/12 update

更改檔案名稱

$ git mv (file) (newfile) 

※2018/12/19 update

查看Hash內更改紀錄

$ git cat-file -p [hash]

※2019/03/15 update

取消已git add 文件

$ git reset HEAD 

※2019/07/01 update

回復至指定commit 紀錄

查看commit 紀錄

$ git log 

查看所有 commit 紀錄

$ git log --oneline 

回復到之前 commit 紀錄

$ git reset --hard "SHA" 

強制推送覆蓋原版本

$ git push -u master origin -f