什么是 Git?
introduction 到 version control and 为什么 Git 是 industry 标准 for tracking 更改.
你将学到
- 什么 version control 是 and 为什么每个 developer 需要它
- 如何 Git tracks 更改到 files over 时间
- difference 之间 Git (tool) and GitHub (platform)
- Distributed 对比 centralized version control 系统
概念讲解
什么是版本控制?
Version control is a system that records changes to files over time so you can recall specific versions later. Without it, you end up with folders full of files like report_final.docx, report_final_v2.docx, report_final_REALLY_FINAL.docx — a nightmare to manage.
Version control lets you:
- Track history — see who changed what, when, and why
- Revert — undo mistakes by going back to any previous state
- Branch — work on features or experiments without affecting the main code
- Collaborate — merge work from multiple people without overwriting each other
What Is Git?
Git is a distributed version control system created by Linus Torvalds in 2005 (the same person who created Linux). It is the de facto standard for software development — over 90% of developers use it.
Git stores snapshots of your project, not just the differences between files. Every commit is a full picture of what your project looked like at that point in time, which makes branching and reverting fast and reliable.
Distributed vs Centralized
Older systems like SVN are centralized — there is one central server, and every developer checks files out from it. If the server goes down, nobody can work.
Git is distributed — every developer has a complete copy of the entire repository history on their machine. You can commit, branch, and view history offline. You only need a network connection to push or pull from a remote.
Git vs GitHub
This is a common point of confusion:
- Git is the command-line tool that runs on your computer. It does the actual version control work.
- GitHub is a web platform that hosts Git repositories and adds collaboration features (pull requests, issues, code review). Other alternatives include GitLab, Bitbucket, and Gitea.
You can use Git without ever touching GitHub — for example, to track a personal project locally. GitHub is just one place to store and share your Git repositories.
Why Learn Git?
Git is non-negotiable in professional software development. Every job posting, every open-source project, every team workflow assumes you know it. Learning the fundamentals early will save you from losing work and from painful conflicts later.
示例代码
# Check if Git is installed and see its version
git --version
# Configure your identity (do this once per machine)
# These get attached to every commit you make
git config --global user.name "Ada Lovelace"
git config --global user.email "[email protected]"
# See all your Git configuration
git config --list
# Get help on any Git command
git help init
git add --help
这些是 首先 commands 你运行之后安装 Git. 配置 commands 设置你的 name and email, 哪个是 embedded in 每个提交所以 people know 谁制作每个更改.
动手试一试
- .gitignore Generator
Generate .gitignore file for 你的 language — 必要 Git companion.
- File Hash Checksum
Git uses SHA-1 hashes internally — see 如何 file hashing 工作.
常见错误
错误写法
Confusing Git 使用 GitHub
正确做法
Git 是 version control tool 那个运行 locally; GitHub 是 web platform 那个 hosts Git 仓库. 你能 use Git 不使用 GitHub, 但你 cannot use GitHub 不使用 Git.
错误写法
不配置用户.name and 用户.email 之前 committing
正确做法
运行 git 配置 --全局用户.name '你的 Name' and git 配置 --全局用户.email '你@示例.com' 之前你的首先提交, or Git 将 refuse 到提交 or use 默认 identity.
相关资源
相关代码片段
- Git Remote Snippet
工作使用 remote 仓库.
相关速查表
- Git Cheatsheet
完整引用的 Git commands.
练习 什么是 Git?
5 个练习
查阅不认识的术语
新手友好的术语表用大白话解释编程术语——变量、函数、DOM、Promise 等等。
动手做项目
通过引导式项目应用所学,含起始代码与解决方案。
解读错误信息
用大白话解释常见错误——什么意思、为什么发生、如何修复。