AnkitG
AnkitG

Reputation: 6568

git squash with a merged file

My git log shows these top 4 commits. The first commit is the one which is formed when i was trying to push code and it asked me to pull code first and then push. (It basically merged).

 commit 71c136f44e5bddd358d86277da730229d871f48c
    Merge: d896439 fe59f57
    Author: Ankit Gupta <[email protected]>
    Date:   Sat Jul 6 21:06:01 2013 +0100

        Merging

    commit d896439d1a33e6c0f3c78f1bf4ad731941c3c0bd
    Author: Ankit Gupta <[email protected]>
    Date:   Sat Jul 6 21:03:20 2013 +0100

        Message1

    commit fe59f57bec7eb2764c4c4e5cd1f5fdc21001bcc5
    Author: Ankit Gupta <[email protected]>
    Date:   Sat Jul 6 21:03:20 2013 +0100

        Message 2

    commit caa12dab636587a741ebc97c4e461d1618de55f9
    Author: Ankit Gupta <[email protected]>
    Date:   Fri Jul 5 16:20:54 2013 +0100

        Message 3

I want to squash all these 4 commits into latest(71c136) and when i do git rebase -i HEAD~4 it shows me

   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
#

Why is it not listing the first commit, and how to squash all 4 of them?

Upvotes: 1

Views: 55

Answers (1)

VonC
VonC

Reputation: 1323483

To merge all four commits into one, you can follow a method similar to the one described in "git: how to insert a commit as the first, shifting all the others?":

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

Upvotes: 1

Related Questions