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


当前回答

什么可能真的很方便: 找到你想在顶部滑动的承诺,说d43e15。

现在使用

git reset d43e15
git commit -am 'new commit name'

其他回答

使用 git rebase -i <after-this-commit> 并在第二次和随后的命令中取代“squash”或“fixup”,如手册中所描述。

在此例子中, <after-this-commit> 是 SHA1 hash 或当前分支的 HEAD 的相对位置,从该分支的 Commits 被分析为 rebase 命令. 例如,如果用户希望从当前 HEAD 查看 5 个 Commits 在过去的命令是 git rebase -i HEAD~5.

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

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

您可以使用 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 &&吉特承诺是,你会得到承诺的消息,以每一个承诺的消息,你正在破坏。

如何回答与此类工作流相关的问题?

许多地方的承诺,混合了多种合并,从大师,最终推到远程,PR和合并到大师由审查员(是的,开发人员将更容易合并 - 经过大师,但团队认为这将减缓过程)。

我没有在这个页面上看到这样的工作流(这可能是我的眼睛)如果我正确地理解复制,多种融合将需要多种冲突解决方案。

所以,这似乎为我们工作。

git pull master git checkout -b new-branch git checkout -b new-branch-temp edit and commit a lot locally, merge master regularly git checkout new-branch git merge --squash new-branch-temp // puts all changes in stage git commit 'one message to rule them all' git push Reviewer does PR and merges to master。

尝试了所有方法提到的这里. 但最终我的问题解决了通过遵循这个链接. https://gist.github.com/longtimeago/f7055aa4c3bba8a62197

$ git fetch upstream
$ git checkout omgpull 
$ git rebase -i upstream/master

 < choose squash for all of your commits, except the first one >
 < Edit the commit message to make sense, and describe all your changes >

$ git push origin omgpull -f