Skip to content

fix(squash): do not commit unstaged changes - #1285

Merged
spacewander merged 3 commits into
tj:mainfrom
jayhemnani9910:fix/squash-keep-unstaged
Nov 18, 2026
Merged

spacewander merged 3 commits into
tj:mainfrom
jayhemnani9910:fix/squash-keep-unstaged

Conversation

@jayhemnani9910

Copy link
Copy Markdown
Contributor

git squash <src> "<msg>" commits with git commit -a, so any tracked file edited but not staged goes into the squash commit too. After git merge --squash or git reset --soft, the squashed changes are already staged, so -a only adds work that was never meant for this commit.

git squash HEAD~2 "squashed"     # with a half-done edit in wip.txt, not staged
git show --stat HEAD             # before: a.txt and wip.txt; after: a.txt only, wip.txt stays modified

Changes

  • bin/git-squash: commit with git commit -m instead of git commit -a -m.
  • tests/git-squash.bats: both forms (branch, and commit on the current branch) leave unstaged edits out of the squash commit. Both tests fail without the fix.

Ran bats ./tests (92 ok) and the steps above on Linux.

AI tools assisted with this contribution.

git squash with a message ran `git commit -a`, so edits that were never staged went into the squash commit. merge --squash and reset --soft already stage the squashed changes.

@spacewander spacewander left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The test runs raw bin/git-squash, which lacks source helper/git-extra-utility. So git_extra_default_branch is "command not found" on stderr and prompt_continuation_if_squashing_default_branch() is a silent no-op. The test passes by luck and would not catch a default-branch detection regression.

Please add test_util.install_command squash as tests/git-delete-merged-branches.bats does.

@spacewander spacewander left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would you also update the doc to emphasize this behavior? I am worried if there is someone still expecting the previous behavior.

@jayhemnani9910

Copy link
Copy Markdown
Contributor Author

Updated the docs in be145d9. The man page and Commands.md now say that unstaged changes stay out of the squash commit, and to git add them first if you want them in.

@spacewander
spacewander merged commit 44c1a07 into tj:main Nov 18, 2026
5 checks passed
@spacewander

Copy link
Copy Markdown
Collaborator

@jayhemnani9910
Merged. Thanks!

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants