實用文章

使用 SSH 的一點紀錄

  • 一開始是因為要一直輸入密碼很麻煩,就想說使用 SSH 一勞永逸

過程

  • 使用 ssh-keygen 生產 SSH Key
    • Image Not Showing Possible Reasons
      • The image file may be corrupted
      • The server hosting the image is unavailable
      • The image path is incorrect
      • The image format is not supported
      Learn More →
  • 將產生的 id_rsa.pub 內容放進 github
    • cat /home/kawa/.ssh/id_rsa.pub 取得要貼到 github 的 Key
    • Image Not Showing Possible Reasons
      • The image file may be corrupted
      • The server hosting the image is unavailable
      • The image path is incorrect
      • The image format is not supported
      Learn More →
  • github.com 加入白名單的樣子
    • ssh-keyscan -t rsa github.com >> ~/.ssh/known_hosts
    • Image Not Showing Possible Reasons
      • The image file may be corrupted
      • The server hosting the image is unavailable
      • The image path is incorrect
      • The image format is not supported
      Learn More →
    • 解決問題的來源網站
  • 即可不輸入密碼 pull & push(寫的時候還沒推過,應該可以)

修改現有專案 pull & push 方式

  • git remote -v
    • 查看現在使用方式
  • git remote set-url origin git@github.com:USERNAME/OTHERREPOSITORY.git

使用紀錄

  • git reset hard (commit-hash)
    • 強制回到該 (commit-hash) 的狀況,這次 merge 要退回而使用
    • 可先用 git checkout (commit-hash) 查看是否是需要的紀錄資料
  • git push -f (remote) (branch-name)
    • 強制線上的紀錄同步
    • 這次使用 git push -f 來強制讓線上的紀錄跟本地的紀錄同步(reset 回舊資料)
  • 刪除本地分支
    • Image Not Showing Possible Reasons
      • The image file may be corrupted
      • The server hosting the image is unavailable
      • The image path is incorrect
      • The image format is not supported
      Learn More →
  • 刪除遠端(ex : github)分支
    • Image Not Showing Possible Reasons
      • The image file may be corrupted
      • The server hosting the image is unavailable
      • The image path is incorrect
      • The image format is not supported
      Learn More →
  • git reset head~

整理 commit

  • git rebase -i HEAD~n
    • 在要整理的分支合併 n 個commit
    • master 練習的時候不能用,不確定問題是啥
      • 好像是不能包含到最初的那個 commit
    • 下完指令後 VScode 會跳出以下畫面
    • Image Not Showing Possible Reasons
      • The image file may be corrupted
      • The server hosting the image is unavailable
      • The image path is incorrect
      • The image format is not supported
      Learn More →
    • 不能從較早時間的 commit 開始 squash,詳細規則待練習
    • 選擇好要 squash 那些 commit 後存檔關掉該頁面後會進入下一步,編輯整合後 commit 訊息
    • 不需要的訊息可在前面加個 # 即可,修改完存檔關閉頁面後應可完成 rebase 整理 commit 的步驟
  • 詳述整理 commit 的網站

同步本地端 & 遠端的分支

覺得之後會用上的參考

  • 取回某次 Commit 的檔案版本
  • 取得整理過後的 log 指令
    • git log pretty=format:"%h%x09%an%x09%ad%x09%s"
      • Image Not Showing Possible Reasons
        • The image file may be corrupted
        • The server hosting the image is unavailable
        • The image path is incorrect
        • The image format is not supported
        Learn More →
      • %h = abbreviated commit hash
      • %x09 = tab (character for code 9)
      • %an = author name
      • %ad = author date (format respects date= option)
      • %s = subject