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

Re: Combining/merging commits

From
Johannes Sixt <j.sixt@viscovery.net>
Date
Apr 15, 2008, 06:37 UTC
Message-ID
<48044D15.6040801@viscovery.net>
In-Reply-To
<8e0b7b96-aee8-45a4-a160-023e92845434@n1g2000prb.googlegroups.com>
xpr1010 schrieb:
> I have made several commits that should really have only been one, but
> there was a lot of back and forth because of my inherent clumsiness.
> Is there any way to combine or merge these commits to one?
Say, you have this commit series:
 ...--A--B--C--D

and you want to combine all of them, i.e. the last 4 commits, into a new one, then you can do:

    # undo commits, but leave working directory unchanged
    $ git reset HEAD~4
    # make a new commit
    $ git commit

But if you want to combine only A,B,C because D should remain a separate commit (i.e. what you want to combine are *not* the last commits), then use git rebase --interactive, in particular, the 'squash' instruction. You would use this todo list:

    pick A
    squash B
    squash C
    pick D
-- Hannes
Previous: xpr1010Next: xpr1010
Message 2 of 3 in “Combining/merging commits”
  1. xpr1010Apr 15, 2008
  2. Johannes SixtApr 15, 2008
  3. xpr1010Apr 15, 2008

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.