Git 路線圖Git Roadmap單元 11Unit 11
進階工具Advanced tools

進階觀念Advanced concepts

UNIT 11 · ADVANCED GIT

進階觀念Advanced concepts

理解 rebase、cherry-pick、tag 與 .gitignore 解決的問題和風險。Understand the problems and risks that rebase, cherry-pick, tags, and .gitignore address.

預計時間Estimated time
30–40 分鐘30–40 minutes
單元類型Unit format
教材+模擬器Lesson + simulator
需要先會Prerequisite
完成前十單元Complete the first ten units

進階指令不是比較厲害,而是解決特定問題

git rebase main 把目前 branch 的 commit 重新播放到新的基底,會產生新的 commit ID。只對尚未共享、自己能控制的歷史使用最安全。

git cherry-pick <commit> 只取出某一個 commit 的變更,在目前 branch 建立新的 commit;它不是搬移原 commit。

git tag v1.0.0 在特定 commit 加上固定名稱,適合標記發布版本。branch 會移動,tag 通常不會跟著移動。

.gitignore 只影響尚未追蹤的檔案。已經 commit 的秘密或建置檔,不會因為後來加入 ignore 規則就自動消失。

rebase、reset 與 force push 都可能改寫共享歷史。工作上先確認團隊規範,再對已分享 branch 操作。

Advanced commands solve specific problems; they are not “better” commands

git rebase main replays the current branch's commits on a new base and creates new commit IDs. It is safest for history that has not been shared and that you control.

git cherry-pick <commit> takes the change from one commit and creates a new commit on the current branch; it does not move the original commit.

git tag v1.0.0 gives a fixed name to a commit, which is useful for marking a release. Branches move; tags usually do not.

.gitignore only affects untracked files. A secret or build file that was already committed does not disappear just because you later add an ignore rule.

rebase, reset, and force push can rewrite shared history. Check your team's rules before using them on a branch others already have.

INTERACTIVE LAB

在安全模擬器裡親手操作

輸入指令後,Terminal、四個區域與 Git 樹會從同一份虛擬狀態同步更新。

A

WORKING DIRECTORY

正在編輯的檔案

  • README.md已提交
  • app.js已提交
  • login.js已提交
  • nav.js已提交
B

STAGING AREA

下一版準備內容

  • Staging Area 是空的
C

LOCAL REPOSITORY

電腦裡的版本

HEAD
→ feature/login
目前 commit
c4
commit 數
4
D

REMOTE REPOSITORY

GitHub 示意狀態

origin
尚未設定
遠端 branch
沒有 commit
網路連線
僅記憶體模擬

教學 Terminal

不會執行真實 Git 或 shell

教學模擬器已就緒。這裡不會執行真實 Git 或讀寫你的檔案。

點一下填入:

VIRTUAL FILES

虛擬檔案編輯器

更多情境工具

LIVE GIT TREE

commit 與 branch

HEAD → feature/login
  1. c4
    HEAD → feature/login
    完成登入提示parent:c2
  2. c3
    main
    調整首頁標題parent:c2
  3. c2
    加入導覽列parent:c1
  4. c1
    建立專案parent:無(第一個 commit)

CHECKPOINT

離開前,確認你能用自己的話說明Before you leave, explain it in your own words

  1. 這些指令改變 Git 的哪一個區域?
  2. Git 樹上的 branch 與 HEAD 移到哪裡?
  3. 失敗時 repository 是否保持原狀?
  4. 真實專案操作前,應先查看什麼?
  1. Which Git area does this command change?
  2. Where do the branch and HEAD move in the Git tree?
  3. Does the repository stay unchanged when the command fails?
  4. What should you check before operating on a real project?

免責聲明:本站內容為個人學習、實作與經驗分享紀錄,部分內容透過 AI 協助修正與整理。由於每位使用者的系統環境、軟體版本、權限設定與操作方式不同,實際結果可能有所差異。請在操作前自行評估風險並備份重要資料。因參考本站內容所造成之任何系統異常、資料遺失、設定錯誤、設備故障、服務中斷或其他直接、間接損失,均由使用者自行承擔,本站與作者不負任何相關責任。

Disclaimer: This site records personal learning, implementation, and experience sharing, with some content edited and organised with AI assistance. Results may differ because every user has a different system environment, software version, permission setup, and workflow. Assess risks and back up important data before trying anything. You are responsible for any system errors, data loss, configuration mistakes, equipment faults, service interruptions, or other direct or indirect losses resulting from using this content.