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


当前回答

尝试了所有方法提到的这里. 但最终我的问题解决了通过遵循这个链接. 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

其他回答

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

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

只需将此 bash 函数添加到.zshrc 文件的 bash。

# Squash last X commits with a Commit message.
# Usage: squash X 'COMMIT_MSG'
# where X= Number of last commits.
# where COMMIT_MSG= New commit msg.
function squash() {
    if [ -z "${1}" -o -z "${2}" ]; then
        echo "Usage: \`squash X COMMIT_MSG\`"
        echo "X= Number of last commits."
        echo "COMMIT_MSG= New commit msg."
        return 1
    fi

    git reset --soft HEAD~"$1"
    git add . && git ci -m "$2" # With 100 emoji
    git push --force
}

然后跑

squash X 'New Commit Message'

你已经完成了。

Anomies 答案很好,但我对此感到不安全,所以我决定添加几张屏幕截图。

步骤 0: git log

查看你在哪里与 git log. 最重要的是,找到第一个 commit 的 commit hash 你不想 squash。

此分類上一篇

步骤一:转动

在我的案例中,执行 git rebase -i(你的哈希):

$ git rebase -i 2d23ea524936e612fae1ac63c95b705db44d937d

步骤2:选择 / 切割你想要的东西

在我的情况下,我想把所有的承诺,这是第一次在时间上。 订单是从第一到最后,所以正如在 git log。 在我的情况下,我想:

此分類上一篇

步骤 3: 调整消息(s)

如果您只选出一个承诺,并解除其余的承诺,您可以调整一个承诺消息:

此分類上一篇

一旦你保存这个(:wq),你已经完成了。

有人提到在 IntelliJ IDEA UI 上做得多容易:

转到 git 窗口 手动选择所有要融入一个的承诺. 右键单击 > Squash 承诺 > 编辑失败的承诺消息 点击左侧的分支名称 > 右键单击 > Push > Force Push

此分類上一篇

除了其他精彩的答案之外,我还想补充一下,Git Rebase -i 如何总是让我与承诺命令混淆 - 老到新或相反? 所以这就是我的工作流:

git rebase -i HEAD~[N], N 是我想加入的命令的数量,从最新的命令开始。 所以 git rebase -i HEAD~5 意味着“将最后 5 命令分成一个新的命令”; 编辑打开,显示我想合并的命令列表。

来源和其他阅读: #1, #2。