Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Git Interactive Rebase - Order of commits and which to pick/squash

Tags:

git

Let's say I have the following:

pick b0bc3ea Issue #1431 - Part 1
pick 606e9bc Issue #1431 - Part 2

Part 2 is obviously the most recent commit. Does it matter which way I squash it? Do I need to squash older into newer, newer into older, or does it matter?

Thanks!

like image 756
Abram Avatar asked Jun 10 '15 23:06

Abram


People also ask

Should you squash before rebasing?

Before rebasing such branches, you may want to squash your commits together, and then rebase that single commit, so you can handle all conflicts at once. Here's how to do that. Imagine you've been working on the feature branch show_birthday , and you want to squash and rebase it onto main .

How do you squash commits when rebasing?

In case you are using the Tower Git client, using Interactive Rebase to squash some commits is very simple: just select the commits you want to combine, right-click any of them, and select the "Squash Revisions..." option from the contextual menu.

How do you pick and commit squash?

Squashing by Interactive Rebase. Git's interactive rebase will list all relevant commits in the default editor. In this case, those are the commits we want to squash. Then we can control each commit and commit message as we want and save the change in the editor.


1 Answers

To combine those two commits, use the following:

pick b0bc3ea Issue #1431 - Part 1
s 606e9bc Issue #1431 - Part 2

The rebase file is processed in order, and the s command squashes that commit into the previous commit (and gives you an opportunity to edit the commit message).

If you tried to make the first commit s, then it would try to squash that into the commit before that one. If you changed the order and picked Part 2 first and tried to squash Part 1 into that, you would probably get merge conflicts.

like image 106
Greg Hewgill Avatar answered Oct 16 '22 14:10

Greg Hewgill