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

Re: Question: is there a short way to merge the last commit to the second last one?

From
Junio C Hamano <gitster@pobox.com>
Date
Jun 8, 2025, 20:55 UTC
Message-ID
<xmqq5xh6vtpp.fsf@gitster.g>
In-Reply-To
<PN3PR01MB959708ED22FE7FE70C17C852B868A@PN3PR01MB9597.INDPRD01.PROD.OUTLOOK.COM>
Aditya Garg <gargaditya08@live.com> writes:
Show 10 quoted lines
> Hi all
>
> This is something I usually come across. Sometimes I make a
> mistake in a commit, and then I create a new commit with a
> correction. After that I git rebase -i and use the fixup option to
> make the fixup commit a part of the main commit.
>
> I was wondering if there is a command, like git fixup or something
> that could make this process easier? I know about git squash but I
> prefer doing fixup.

If your "After that" is "immediately after that before piling any more commits on top of the history", then the standard answer would be "rebase --autosquash", i.e.

 ... work work work
 $ git commit [options and arguments]
 ... oops that needs further change
 ... work more
 $ git commit -m 'fixup' [options and arguments]
 $ git rebase --autosquash HEAD~2
But if it is truly immediately after that", then
 ... work work work
 $ git commit [options and arguments]
 ... oops that needs further change
 ... work more
 $ git commit --amend [options and arguments]
would be even simpler.
Previous: Aditya Garg
Message 10 of 10 in “Question: is there a short way to merge the last commit to the second last one?”
  1. Aditya GargJun 8, 2025
  2. brian m. carlsonJun 8, 2025
  3. Aditya GargJun 8, 2025
  4. Phillip WoodJun 8, 2025
  5. Aditya GargJun 8, 2025
  6. brian m. carlsonJun 8, 2025
  7. Aditya GargJun 9, 2025
  8. Phillip WoodJun 9, 2025
  9. Aditya GargJun 9, 2025
  10. Junio C HamanoJun 8, 2025

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.