Skip to content

合并

一句话解释

合并 组合 更改 从 one 分支 到 another, uniting two 行 的 development.

用大白话说

合并 brings 提交从 one 分支到 another. 当你的 feature 是 finished, 你切换到 main and 运行 git merge feature/login to fold the feature's changes into the main line. Git tries to combine the histories automatically.

If both branches changed the same lines, Git cannot decide which version wins and reports a merge conflict. You must open the conflicted files, choose the correct version, and commit the resolution. Good communication and small, frequent merges reduce conflicts.

An alternative to merging is rebasing, which replays your commits on top of the target branch for a linear history. Merging preserves the branch structure with a merge commit; rebasing rewrites history. Both are valid — choose based on your team's convention.

示例

bash
# Switch to the target branch
git checkout main

# Merge the feature branch into main
git merge feature/login

# If there are conflicts, Git pauses:
# 1. Open the conflicted files and resolve them
# 2. Stage the resolved files
git add .
# 3. Complete the merge
git commit

git 合并 组合 feature 分支 到 主要. 如果 conflicts occur, resolve 它们, stage, and 提交.

常见混淆

  • 容易混淆的对象: rebase

    关键区别: 合并 组合 two 分支 and 创建 合并 提交, preserving 分支 history. rebase replays 你的 提交 on 顶部 的 another 分支, producing linear history 但 rewriting 提交 hashes. 合并 是 safer for shared 分支; rebase gives cleaner history.

相关术语

相关资源

相关课程

解读错误信息

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

查看错误

← 返回术语表