public inbox for git@vger.kernel.org 
 help / color / mirror / Atom feed
From: "brian m. carlson" <sandals@crustytoothpaste•net>
To: Aditya Garg <gargaditya08@live•com>
Cc: phillip.wood@dunelm•org.uk,
	Phillip Wood <phillip.wood123@gmail•com>,
	"git@vger•kernel.org" <git@vger•kernel.org>
Subject: Re: Question: is there a short way to merge the last commit to the second last one?
Date: Sun, 8 Jun 2025 21:43:01 +0000	[thread overview]
Message-ID: <aEYD5X940Li_H7KU@tapette.crustytoothpaste.net> (raw)
In-Reply-To: <PN3PR01MB9597D380178A875C6FFA90E0B868A@PN3PR01MB9597.INDPRD01.PROD.OUTLOOK.COM>

[-- Attachment #1: Type: text/plain, Size: 1978 bytes --]

On 2025-06-08 at 19:35:24, Aditya Garg wrote:
> 
> 
> On 9 June 2025 1:01:19 am IST, Phillip Wood <phillip.wood123@gmail•com> wrote:
> >On 08/06/2025 19:57, brian m. carlson wrote:
> >> 
> >> If your goal is to just do the fixups and squash and not anything else
> >> interactive, then you can do this:
> >> 
> >>      GIT_SEQUENCE_EDITOR=true git rebase -i --autosquash
> >
> >Just a quick note to say that since git v2.44.0 you can just run
> >
> >	git rebase --autosquash
> >
> 
> Silly question but how does it get to know what is the fixup commit?

That's actually a great question.  When you do `git commit --squash
REVISION`, it takes the summary of the commit specified by `REVISION`
and precedes it with `squash! `, and for `--fixup`, it does `fixup! `.

Then, it's just a matter of re-ordering the squash or fixup commits in
order after the commit with the corresponding summary.

So with this shell script:

----
#!/bin/sh

git init --object-format=sha256 test-repo
cd test-repo

echo abc >file.txt
git add file.txt
git commit -m 'Initial commit'

echo def >file.txt
git add file.txt
git commit --fixup HEAD
git show
----

You get something like this:

----
Initialized empty Git repository in /tmp/user/1000/test-repo/.git/
[dev (root-commit) 7327102] Initial commit
 1 file changed, 1 insertion(+)
 create mode 100644 file.txt
[dev 8bdd271] fixup! Initial commit
 1 file changed, 1 insertion(+), 1 deletion(-)
commit 8bdd271b6d4e22b7ca697c2d4499fd3e0825977d7d2c917b92e1f1f12383f52c
Author: brian m. carlson <sandals@crustytoothpaste•net>
Date:   Sun Jun 8 21:41:43 2025 +0000

    fixup! Initial commit

diff --git a/file.txt b/file.txt
index e0ef420..559afde 100644
--- a/file.txt
+++ b/file.txt
@@ -1 +1 @@
-abc
+def
----

Of course, `--autosquash` does require using `--fixup` and `--squash` or
otherwise naming the commits that way.
-- 
brian m. carlson (they/them)
Toronto, Ontario, CA

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 325 bytes --]

  reply	other threads:[~2025-06-08 21:43 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-06-08 18:30 Question: is there a short way to merge the last commit to the second last one? Aditya Garg
2025-06-08 18:57 ` brian m. carlson
2025-06-08 19:09   ` Aditya Garg
2025-06-08 19:31   ` Phillip Wood
2025-06-08 19:35     ` Aditya Garg
2025-06-08 21:43       ` brian m. carlson [this message]
2025-06-09  4:29         ` Aditya Garg
2025-06-09 10:06     ` Phillip Wood
2025-06-09 10:35       ` Aditya Garg
2025-06-08 20:55 ` Junio C Hamano

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=aEYD5X940Li_H7KU@tapette.crustytoothpaste.net \
    --to=sandals@crustytoothpaste$(echo .)net \
    --cc=gargaditya08@live$(echo .)com \
    --cc=git@vger$(echo .)kernel.org \
    --cc=phillip.wood123@gmail$(echo .)com \
    --cc=phillip.wood@dunelm$(echo .)org.uk \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox