Try   HackMD

Git&GitHub(3/3) Day 4 五倍紅寶石(第八屆共筆)(2021/7/01)

Git:

移動:

相對定位:

可以回到前面狀態,使用分支名或HEAD+以下符號。
^(caret)往前一步、也可用^^、^^^。
~(tilde)+任意數字 = 往前任意步。

reset:

git reset = become = 變成目標的形狀。

When?
一般用來復原做錯的專案(新的專案reset變舊的),
若反向操作,渣渣會變成相反的(add => delete)。

相較於checkout只有HEAD會移動,reset有兩個東西會移動:

  1. HEAD會移動
  2. 被HEAD指到的分支也會跟著移動
    reset後原commit點內容還在,但因沒人看管,會變透明人。

哪些指令會移動HEAD?

  • git commit
  • git switch / checkout
  • git merge
  • git rebase
  • git reset

GitHub:

GitHub≠Git,主要是拿來做遠端備份,以及多人協作的好工具。
HTTPS登入:帳密。
SSH登入:一對鑰匙,public key可公開;private key要自己收好不可外流。

用法:

  1. 終端機上進入想上傳的目錄。
  2. GitHub上New Repository。
  3. 依目錄有無版控自行選擇要複製哪段CODE。
  4. 終端機上一步一步輸入。
  5. 輸完git remote add origin可用git remote -v檢查有無成功。
  6. 專案Commit完git push上去。
  7. 若要更新本機進度則git pull下來。

各指令意義:
git remote add origin + 某個網址 :
新增一個名為origin的遠端節點,此節點會指向某個網址。(origin為預設書籤,可幫他改任意名稱)

git push -u origin main:cat :
把本地main分支推到origin遠端節點,並在線上創建一個cat分支。
-u用來把origin跟cat自動設定成遠端節點及分支,
之後push時只要打git push即可。

git pull origin main :
去origin這個遠端節點抓main分支下來,在本地創建origin/main這個分支,然後把main跟他合併

git stash 可以把未完成檔案暫存於暫存區

Git指令:

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指令原檔:https://www.xmind.net/m/WEaxjH

tags: Git