git
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseGit
Git
Git is the foundation of modern software. In 2025, features like Sparse Checkout and Scalar (for monorepos) are becoming mainstream.
Git是现代软件开发的基础。到2025年,Sparse Checkout和Scalar(针对单体仓库)等功能正成为主流。
When to Use
使用场景
- Always: Use it for everything. Text files, config, code.
- Bisect: Finding bugs by binary search.
- 始终使用:所有内容都用Git管理,包括文本文件、配置文件和代码。
- Bisect命令:通过二分查找定位Bug。
Core Concepts
核心概念
Graph
提交图
Commits form a DAG (Directed Acyclic Graph).
提交记录构成一个有向无环图(DAG)。
Rebase vs Merge
Rebase与Merge对比
- Merge: Preserves history, creates bubbles.
- Rebase: Rewrites history, linearizes.
- Merge:保留历史记录,会产生分支节点(气泡状)。
- Rebase:重写历史记录,使提交历史线性化。
Worktrees
Worktrees(工作树)
Checkout multiple branches of the same repo in different folders simultaneously.
可在不同文件夹中同时检出同一仓库的多个分支。
Best Practices (2025)
2025年最佳实践
Do:
- Use /
git switch: The modern alternatives to the overloadedgit restore.git checkout - Use : Speed up fetch/clone in the background.
git maintenance - Sign Commits: Use SSH keys to sign commits ().
Commit Signing
Don't:
- Don't force push to shared branches: is the safer alternative.
git push --force-with-lease
建议做法:
- 使用/
git switch:替代功能过载的git restore的现代命令。git checkout - 使用:在后台加速拉取/克隆操作。
git maintenance - 签署提交:使用SSH密钥签署提交()。
Commit Signing
不建议做法:
- 不要强制推送到共享分支:是更安全的替代方案。
git push --force-with-lease