git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: squash commits deep down in history

From
Phil Hord <phil.hord@gmail.com>
Date
Nov 4, 2014, 17:25 UTC
Message-ID
<CABURp0p_VzxXjFMEqLNg0MgY55akCmUJk7mvSG7JuuLp=r8YbA@mail.gmail.com>
In-Reply-To
<trinity-6a57d894-cc4f-4213-9c51-5c73de2501d0-1414067657189@3capp-gmx-bs48>
On Thu, Oct 23, 2014 at 8:34 AM, Henning Moll <newsScott@gmx.de> wrote:
Show 11 quoted lines
> Hi,
>
> i need to squash several commits into a single one in a automated way. I know that there is interactive rebase, which can also be automated using GIT_SEQUENCE_EDITOR. Unfortunately my history is very large and i need to squash deep down in the history several times. So using interactive rebase seems not to be the right tool.
>
> I wonder if i can solve this task using filter-branch? I have a file that list the SHA1s for each squash operation per line. All SHA1s of a line are in chronological order (youngest to oldest), or in other words: the first SHA1 is the child of the second, and so on.
>
> | ab4423e 3432343 3234252
> | 2324342 5232343
> | ...
>
> Lets say there are N lines in that file. Each line means: squash all SHA1s of this line into the first (or last) SHA1 of this line.

I've often felt there should be some simple commands to do these kinds of edits. For example, it is easy to amend HEAD, but an order-of-magnitude more difficult to amend HEAD^. I imagine commands like this:

   git rebase --reword HEAD^
   git rebase --edit some-old-commit
   git rebase --squash ab4423e 3432343 3234252

But each time I think of implementing one of these I am daunted by the many exceptional cases.

> Performing this task with rebase would require N rewritings of the history. So e.g. HEAD (but many others too) would be rewritten N times even if it is not directly part of a line. My thinking is, that a filter-branch can do this in a single rewrite and therefore would be much more performant.
>
> How can i solve this? Any ideas?

I know you solved this already with filter-branch, but that seems like a complicated solution to me. I think the --interactive rebase would have been useful for you. You should keep in mind that you do not need to repeat the command multiple times for your multiple squashes. For example, if your to-do list looks like this simple example:

pick 0000000 pick ab4423e pick 3432343 pick 3234252 pick 0000001 pick 0000002 pick 2324342 pick 5232343 pick 0000003

I think you could get the desired effect by changing it to this:

pick 0000000 pick ab4423e squash 3432343 squash 3234252 pick 0000001 pick 0000002 pick 2324342 squash 5232343 pick 0000003

And then running that all in one interactive rebase.  Does that make sense?
Phil
Previous: Jakub Narębski
Message 5 of 5 in “squash commits deep down in history”
  1. Henning MollOct 23, 2014
  2. Johannes SixtOct 23, 2014
  3. Henning MollOct 23, 2014
  4. Jakub NarębskiOct 24, 2014
  5. Phil HordNov 4, 2014

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.