Skip to content

分支

一句话解释

分支 是 independent 行 的 development 那个 lets 你 工作 on 更改 不使用 affecting 主要 history.

用大白话说

分支是 separate timeline 的提交. 当你 创建分支, 你能 制作提交 on 它不使用 touching 主要行 (通常 called main or master). This lets you develop a feature or fix a bug in isolation, then merge it back when ready.

Branches are cheap and fast in Git — creating one is just a pointer move. A common workflow is to create a feature/登录 branch, build the feature, then open a pull request to merge it into 主要. If the feature is rejected, you simply discard the branch.

The branch you are currently on is called the "current" or "检查 out" branch. Switch branches with git checkout or git 切换. List all branches with git 分支, and create a new one with git 分支 <name> or git checkout -b <name>.

示例

bash
# Create and switch to a new branch
git checkout -b feature/login

# Make some commits on the branch...
git add .
git commit -m "Add login form"

# Switch back to main
git checkout main

# List all branches
git branch

git checkout -b 创建 and 切换 到 新 分支. 提交 on 它 做 不 affect 主要 直到 你 合并.

常见混淆

  • 容易混淆的对象: Fork

    关键区别: 分支 是 行 的 development 在内 单个 仓库; Fork 是 完整 复制 的 仓库 under 你的 own account. 分支 是 lightweight and 局部; Fork 是 服务器-边 and used for contributing 到 others' 项目.

相关术语

相关资源

相关课程

相关项目

解读错误信息

用大白话解释常见错误——什么意思、为什么发生、如何修复。

查看错误

← 返回术语表