git-prompt

參考教學:https://docs.webmix.cc/git
實際學習 git : https://learngitbranching.js.org/

說明:
commit 會占空間
branch 非常不佔空間(早點建立 branch!經常建立 branch!)

  1. git add

  2. git commit

  3. git status

  4. 新增 branch (可以以資料夾的方式分支 features/login)
    git branch <取名>

  5. 查看所有 branch (*代表正在處於的 branch)
    git branch

  6. 切換分支
    git switch <branch 名字>
    git checkout <branch 名字> (切換分支
    git checkout (檢出特定提交
    git checkout
    git checkout HEAD^

git checkout (還原文件

  1. 返回上一步
    git restore <檔案名稱>
    git reset <HEAD~1> ((取消修改,回到上一步,但是對 remote branch 無效
    git revert HEAD (( 取消修改並且把這個狀態分享給別人

  2. 刪除檔案
    git rm

  3. 將分支(branch)重新設定到過去的特定 Commit ID。
    git reset

  4. 回溯 (不刪除檔案)
    git switch –detach

  5. 查看 log
    git log
    git log –oneline
    git log –oneline -2
    git log –graph

  6. 給予標籤(v1 /v2 / v1.1 等)
    git tag <版本名稱>
    git show <版本名稱>

  7. 把別的分支合併到要合並的分支 ,先進入要被合併的分支
    git merge
    git merge <要合並的分支名稱/commit id>

遇到衝突 https://docs.webmix.cc/git/4-git-ji-ben-cao-zuo/4.14-he-bing-yu-dao-chong-tu
git merge –abort (放棄合併)

  1. 合併 commit
    git rebase -i HEAD~<數字>
    git rebase main
    git rebase (跟上進度)

解完衝突後進行
git rebase –continue

  1. git stash (封存)

  2. cherry-pick (( 建議先 checkout 到你要的分支再做。

練習 1

git status ( 確保乾淨 )
git branch <新分支名稱> ( 開啟新分支 )
git switch <分支名稱> (切換到該 branch)
修改檔案…..
git add <檔案名稱> ( . 代表全部 、*.<檔案類型>)
git commit -m “<訊息>”
git switch <主分支> (切換回來主分支)
git merge <剛剛修改的分支> (進行合併)
git tag <版本名稱>
git branch -d <分支名稱> 刪除不要的 branch/可選擇

練習 2
git log
git restore
git reset
git rm
git switch detach

:wq (存檔)


转载请注明来源,欢迎对文章中的引用来源进行考证,欢迎指出任何有错误或不够清晰的表达。可以邮件至 kimfei2014@gmail.com
github