我如何将最后的N承诺集成到一个承诺中?


当前回答

簡單的單線,總是工作,因為你現在在你想要的分支,主是它起源的分支,最新的承諾包含承諾訊息和作者你想使用:

git reset --soft $(git merge-base HEAD master) && git commit --reuse-message=HEAD@{1}

其他回答

如果您使用 TortoiseGit,您可以将函数结合到一个承诺:

打开 TortoiseGit 背景菜单 选择显示日志 标记日志视图中的相关任务 从背景菜单中选择组合到一个任务

此分類上一篇

此功能自动执行所有必要的单 git 步骤 不幸的是,仅适用于 Windows。

我建议尽可能避免吉特重新设置 - 特别是对于吉特新闻. 除非你真的需要自动化一个过程,基于几个承诺,有一个不那么异国情调的方式。

将被排除的承诺放在一个工作分支(如果它们还没有) - 使用 gitk 为此 查看目标分支(例如“主”) git merge --squash (工作分支名称) git commit

承诺的消息将基于 squash 预受欢迎。

如果您正在使用 GitUp,选择您想要与其父母合并的承诺,并按下 S. 您必须为每个承诺做一次,但它比与正确的命令线引发更简单。

如果您不关心承诺信息的承诺之间,您可以使用

git reset --mixed <commit-hash-into-which-you-want-to-squash>
git commit -a --amend

您可以使用 git merge --squash 为此,这比 git rebase -i 略有优雅。

警告: 首先,请确保您完成工作 - 检查 git 状态是干净的(因为 git 重新设置 - 硬将抛弃错误和错误的变化)

然后:

# Reset the current branch to the commit just before the last 12:
git reset --hard HEAD~12

# HEAD@{1} is where the branch was just before the previous command.
# This command sets the state of the index to be as it would just
# after a merge from that commit:
git merge --squash HEAD@{1}

# Commit those squashed changes.  The commit message will be helpfully
# prepopulated with the commit messages of all the squashed commits:
git commit

git merge 的文档详细描述了 --squash 选项。


更新:这个方法的唯一真正优点,比克里斯·约翰森(Chris Johnsen)在他的回答中提出的更简单的吉特重新设置 --soft HEAD~12 &&吉特承诺是,你会得到承诺的消息,以每一个承诺的消息,你正在破坏。