1

我的 git 日志显示了这些前 4 个提交。第一次提交是在我尝试推送代码时形成的,它要求我先提取代码然后推送。(它基本上合并了)。

 commit 71c136f44e5bddd358d86277da730229d871f48c
    Merge: d896439 fe59f57
    Author: Ankit Gupta <ankit.gupta8898@gmail.com>
    Date:   Sat Jul 6 21:06:01 2013 +0100

        Merging

    commit d896439d1a33e6c0f3c78f1bf4ad731941c3c0bd
    Author: Ankit Gupta <ankit.gupta8898@gmail.com>
    Date:   Sat Jul 6 21:03:20 2013 +0100

        Message1

    commit fe59f57bec7eb2764c4c4e5cd1f5fdc21001bcc5
    Author: Ankit Gupta <ankit.gupta8898@gmail.com>
    Date:   Sat Jul 6 21:03:20 2013 +0100

        Message 2

    commit caa12dab636587a741ebc97c4e461d1618de55f9
    Author: Ankit Gupta <ankit.gupta8898@gmail.com>
    Date:   Fri Jul 5 16:20:54 2013 +0100

        Message 3

我想将所有这 4 个提交压缩到 latest(71c136) 中,当我这样做时git rebase -i HEAD~4它会告诉我

   pick 56e3419 Message 4
    pick caa12da Message 3
    pick d896439 Message 2
    pick fe59f57 Message 1
# Rebase ebabdfb..71c136f onto ebabdfb
#
# Commands:
#  p, pick = use commit
#  r, reword = use commit, but edit the commit message
#  e, edit = use commit, but stop for amending
#  s, squash = use commit, but meld into previous commit
#  f, fixup = like "squash", but discard this commit's log message
#  x, exec = run command (the rest of the line) using shell
#

为什么它没有列出第一个提交,以及如何压缩所有 4 个提交?

4

1 回答 1

1

要将所有四个提交合并为一个,您可以遵循类似于“ git:如何将提交作为第一个插入,转移所有其他提交? ”中描述的方法:

git symbolic-ref HEAD refs/heads/newroot
git rm --cached -r .
git clean -f -d
# All commits should be listed then: you can squash them
git rebase --interactive --onto newroot --root master
git branch -d newroot
于 2013-07-06T22:57:25.387 回答