Skip to content

Instantly share code, notes, and snippets.

@duboisf
Created September 18, 2025 13:42
Show Gist options
  • Select an option

  • Save duboisf/ecb422caa250f33b4df1317f798bf392 to your computer and use it in GitHub Desktop.

Select an option

Save duboisf/ecb422caa250f33b4df1317f798bf392 to your computer and use it in GitHub Desktop.

HOWTO: ammend a git commit with fixup instead of interactive rebase

I did some modifications to the AGENTS.md file in my GitHub repo and I want to add this change to the commit that added this file in my feature branch. Normally I would:

  • Stash my changes
  • Run git rebase -i main and mark the target commit with edit
  • When the rebase stops at the target commit, I would apply my stashed changes and amend the commit with git commit --amend
  • Finally, I would continue the rebase with git rebase --continue

But there is a much easier way to do this! I can use the --fixup option of git commit to create a new commit that will be automatically squashed into the target commit during a rebase.

Here's an example commit history of my feature branch:

a22cedc fix: add default target
ac42e65 fix: refactor service_test.go with test fixture and grouping
d03eec5 fix: use interface for client creator
848a195 fix: refactor diff_generator_test.go
74ae314 feat: add AGENTS.md and rename readme.md to README.md
fbd3df2 fix: refactor diffable_test.go to use fixture
57cf567 feat: add cover target to Makefile
69fdec3 feat(ci): add coverage diff check for PRs
60f6ae1 (tag: v1.3.0, origin/main, origin/HEAD, main) Merge pull request #38 from fd/feat/makefile

I want to commit my changes to the commit with the message feat: add AGENTS.md and rename readme.md to README.md, which has the hash 74ae314. To do this, you can run either of the following commands:

gci --fixup=74ae314
# or
git commit --fixup=':/AGENTS.md'

The second form is very convenient because it allows you to specify the commit by searching for a string in the commit message. In this case, :/AGENTS.md will find the commit that contains "AGENTS.md" in its message.

Then, when you are ready to squash the fixup commit into the target commit, you can run:

git rebase -i --autosquash main

And you are done!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment