Author(作者)
最初编写该提交内容的人,通常是你用 git commit 提交时设置的名字。
git config --global user.name "YourName"
git config --global user.email "your@email.com"
Committer(提交者)
最终将改动合并进仓库的人。
git commit -m "fix: bug in login"
# %an = Your Name
# %cn = Your Name
git cherry-pick abc1234 # 别人用 cherry-pick 把你的提交应用到另一个分支:
# %an = Your Name(你写的代码)
# %cn = Other Person(他执行了 cherry-pick)
git checkout feature # feature 是别人提交的代码
git rebase main # 你 rebase 别人写的代码
# %an = Other Person(原提交作者)
# %cn = Your Name(你执行了 rebase)
git merge --no-commit feature # 你 --no-commit 别人代码
git commit -m "commit commit"
# squash 合并丢弃原始提交信息,新提交由你创建
# %an = Your Name(你是最终手动提交的人)
# %cn = Your Name(你是最终手动提交的人)
git merge --squash feature # 你 --squash 别人代码
git commit -m "commit commit"
# %an = Your Name(你是最终手动提交的人)
# %cn = Your Name(你是最终手动提交的人)
git merge branch1 branch2 branch3 # 你 多分支合并
# 只有生成的合并提交由你负责,其他提交保持不变
# 原始提交:
# %an = Other Person(不会改变)
# %cn = Other Person(不会改变)
# 合并提交:
# %an = Your Name(你是最终提交的人)
# %cn = Your Name(你是最终提交的人)
git merge --ff-only release # 你 --ff-only merge 别人代码
# 快进成功 ⇒ 没有新提交,只是移动指针,不修改任何提交内容
# %an = Other Person(不会改变)
# %cn = Other Person(不会改变)
git merge --no-ff release # 你 --no-ff merge 别人代码
# %an = Your Name(你是最终提交的人)
# %cn = Your Name(你是最终提交的人)
git merge --ff release # 你 --ff merge 别人代码
# 依赖到底 ff 还是 no-ff
Pull Request 合并(GitHub/Gitee 等平台自动设置 committer)
Create a merge commit(默认合并方式):创建一个合并提交,保留原始分支的所有提交历史。
# author (%an) = 点击“Merge”按钮的人(即你)
# committer (%cn) = 平台系统账号(如 GitHub 的 web-flow 或 github-actions[bot])
Squash and merge:将 PR 所有提交压缩成一个新提交,然后合并到目标分支。
# author (%an) = 点击“Merge”按钮的人(即你)
# committer (%cn) = 平台系统账号
Rebase and merge:将 PR 分支 rebase 到目标分支上,线性地合并所有原始提交
# author (%an) = 原始提交的作者
# committer (%cn) = 平台系统账号