3

How can I combine 1st commit with 4th commit in git using 'git rebase'. From what I read here http://gitready.com/advanced/2009/02/10/squashing-commits-with-rebase.html, the 'squash' command in 'git rebase' only meld into previous commit.

in git, I have

$ git log
commit 9a30d13
commit 4a6729e
commit 4a6729e
commit 4a6729e
commit a610898

Basically, I want changes from 9a30d13 to combine with changes in a610898, so that the new history is

$ git log
commit 4a6729e
commit 4a6729e
commit 4a6729e
commit a610898 + 9a30d13

I have not pushed anything.

Thank you.

0

1 Answer 1

4

When you do an interactive rebase as described at your link, you can reorder the commits, too. Once you change the order, you can squash 9a30d13 into a610898.

When the interactive rebase comes up, it will look something like this (with the oldest commits on top):

pick a610898 Message A
pick 4a6729e Message B
pick 4a6729e Message C
pick 4a6729e Message D
pick 9a30d13 Message E

You then reorder them:

pick a610898 Message A
pick 9a30d13 Message E
pick 4a6729e Message B
pick 4a6729e Message C
pick 4a6729e Message D

And change 9a30d13 to squash rather than pick:

pick a610898 Message A
squash 9a30d13 Message E
pick 4a6729e Message B
pick 4a6729e Message C
pick 4a6729e Message D

Save & exit, and you're done. You'll get a chance to enter a new commit message for your new a610898 + 9a30d13 commit.

Sign up to request clarification or add additional context in comments.

3 Comments

@0x90, what does that mean?
I meant if you could publish all commands and outputs from shell, but it looks like you did it. did you mean to use git before each line?
no – what you are seeing there is the editor you get when you run git rebase --interactive **somesha**

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.