5

I am sort of new to rebasing and definitely haven't squashed commits before.

While checked out to my local branch called 'whatever', I then do a git add and git commit, then rebase.

I guess this is the right way to rebase or at least one way:

git rebase -i development 

development is our mainline branch that we rebase our commits on top of. When I do that command I get: enter image description here

I have to scroll down to see the latest commits that I just tried to rebase on top of the development branch:enter image description here

I'm no sure what to do at this point. I've obviously committed my changes, and then did a rebase. Is there a command to squash and what do I squash?? I don't want to squash the entire history of the development branch. Is squash something you do before you rebase? I'm lost a bit.

0

1 Answer 1

6

You should just be able to change the word "pick" to "squash" in order to squash the commit marked "squash" into the preceding commit.

Git Documentation: Rewriting History

An example:

$ git log --oneline acb05b3 Some final commit. 4968dbd Fixing an error in commit df89a81. df89a81 Something committed too early. c365eab Another commit... 625889f A commit... 70f29fd The beginning. 

I want to rebase onto 3 commits before the most recent:

$ git rebase -i HEAD~3 

This gives the following text in a text editor:

pick df89a81 Something committed too early. pick 4968dbd Fixing an error in commit df89a81. pick acb05b3 Some final commit. # Rebase c365eab..acb05b3 onto c365eab (3 command(s)) 

Which I change to this:

pick df89a81 Something committed too early. squash 4968dbd Fixing an error in commit df89a81. pick acb05b3 Some final commit. # Rebase c365eab..acb05b3 onto c365eab (3 command(s)) 

Upon exiting, I then get another editor containing this:

# This is a combination of 2 commits. # The first commit's message is: Something committed too early. # This is the 2nd commit message: Fixing an error in commit df89a81. # Please enter the commit message for your changes. Lines starting # with '#' will be ignored, and an empty message aborts the commit. 

Which I change to this:

# This is a combination of 2 commits. # The first commit's message is: This is the squashed commit. It and everything after it get new commit hashes. # Please enter the commit message for your changes. Lines starting # with '#' will be ignored, and an empty message aborts the commit. 

Now if I look at my new history:

$ git log --oneline 8792fef Some final commit. df775c4 This is the squashed commit. It and everything after it get new commit hashes. c365eab Another commit... 625889f A commit... 70f29fd The beginning. 
Sign up to request clarification or add additional context in comments.

10 Comments

the weird things is I can't see all the picks in the list, is there way to scroll up?
Which commits are missing, what is your current branch, and how does the current branch differ from branch development? git rebase -i development should attempt to rebase every commit in your current branch that is not already part of branch development.
so I'm checked out to 'mybranch'. I did a couple git . and git commits. So my local branch has a few commits. Then I did a rebase on the development branch (not my branch). So when I rebase I'm seeing the development branch's history in that pic
ah ok if I scroll down I can see my latest commits. not sure why it doesn't just bring me to the bottom in the first place. I'll add another screenshot
Ah, it may just have been the ordering that is the source of confusion. Interactive rebase lists commits in the opposite order to git log. I.e. Oldest first, newest last.
|

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.