進階指令不是比較厲害,而是解決特定問題
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.