aider icon indicating copy to clipboard operation
aider copied to clipboard

Enhancement: Only commit staged files if files have been staged.

Open nevercast opened this issue 1 year ago • 10 comments

Issue

I appreciate Aider's commit messages; they often surpass Copilot's, which seems to have declined recently.

In my workflow, I stage the files I intend to commit, create a commit message for them, and then proceed to stage the next set of files.

I'm considering using Aider's /commit feature for this process. However, Aider currently stages and commits all modified files.

This doesn't align with my method of working alongside Aider, where I prefer to commit only the staged files, not every changed file.

Additionally, I've observed that Aider overlooks new files during /commit. If /commit is designed to stage and commit all changes, excluding new files appears to be an oversight.

Finally, during refactors, I often end up with numerous uncommitted files. I need to segment these into several commits. Even if I wanted Aider to commit everything, I would encounter a "diff too large" error.

Version and model info

Aider v0.43.4 Models: openrouter/anthropic/claude-3.5-sonnet with diff edit format, weak model gpt-3.5-turbo Git repo: .git with 505 files Repo-map: using 1024 tokens VSCode terminal detected, pretty output has been disabled. Use /help to ask for help, run with --help to see cmd line args

nevercast avatar Jul 18 '24 03:07 nevercast

I want this too!

zhangyi1357 avatar Aug 10 '24 07:08 zhangyi1357

I want this too!

I have added new PR with command /scommit for exactly this: https://github.com/Aider-AI/aider/pull/2763

easyrider avatar Jan 03 '25 13:01 easyrider

instead of scommit, it would be more ergonomic if commit just behaved like git commit and only considered staged files by default

OttoAllmendinger avatar Jan 24 '25 10:01 OttoAllmendinger

instead of scommit, it would be more ergonomic if commit just behaved like git commit and only considered staged files by default

...or all modified files if none are staged.

akaihola avatar Jan 24 '25 16:01 akaihola

Initially, I also wanted this kind of functionality. But after trying two PRs and finding they didn't work ideally, I began to think that /commit and --commit might just be "extras" that aider provides.

Aider uses git to allow users to undo AI changes at any time. Helping users with commit tasks seems to deviate from aider's main purpose.

If we want to simplify git commit work, perhaps we shouldn't expect this from aider. Wouldn't it be better to use dedicated tools👇️ for that?

https://github.com/jnsahaj/lumen https://gitbrain.dev/

kaorukobo avatar Mar 16 '25 10:03 kaorukobo

Until the implementation arrives, as a quick & dirty solution I've changed repo.py like this:

diff --git a/aider/repo.py b/aider/repo.py
--- a/aider/repo.py
+++ b/aider/repo.py
@@ -147,8 +147,6 @@
                 except ANY_GIT_ERROR as err:
                     self.io.tool_error(f"Unable to add {fname}: {err}")
             cmd += ["--"] + fnames
-        else:
-            cmd += ["-a"]
 
         original_user_name = self.repo.git.config("--get", "user.name")
         original_committer_name_env = os.environ.get("GIT_COMMITTER_NAME")
@@ -247,7 +245,7 @@
 
         try:
             if current_branch_has_commits:
-                args = ["HEAD", "--"] + list(fnames)
+                args = ["--cached", "HEAD", "--"] + list(fnames)
                 diffs += self.repo.git.diff(*args)
                 return diffs
 
@@ -255,7 +253,6 @@
             index_args = ["--cached"] + wd_args
 
             diffs += self.repo.git.diff(*index_args)
-            diffs += self.repo.git.diff(*wd_args)
 
             return diffs
         except ANY_GIT_ERROR as err:

maliayas avatar Apr 15 '25 22:04 maliayas

any ETA for arrival of this? I dislike the inconsistent commits from opencommit and would love for this to be default behaviour to replace oco

jakob1379 avatar Jul 03 '25 07:07 jakob1379

As a workaround for this in my script I'm stashing the unstaged changes using a named stash with a unique value and then dropping them using a trap in bash (so it always gets dropped). If anyone is interested, here's the script: https://github.com/nieomylnieja/dotfiles/blob/main/scripts/aider-commit.bash.

nieomylnieja avatar Jul 22 '25 08:07 nieomylnieja

Meanwhile I have found a pretty simple workflow:

  1. stash worktree (stashes unstaged changes) with git stash push --keep-index --include-untracked -m "WIP unstaged for commit" Ofcause git aliased as git stash-wip
  2. aider commit 3 pop stash. This is quickly enough that I do not find it annoying to do the extra operations when committing, as I am forced to consider what parts should actually be part of the commit. This is what some would consider "good practice".

jakob1379 avatar Aug 12 '25 07:08 jakob1379

An alternative solution - CLI one liner for those who don't mind clean making final changes in $EDITOR

aider --no-gui --no-detect-urls --no-stream --no-pretty --message "/ask Generate a concise commit message for these changes: $(git diff --staged)" | git commit -F - -

If anyone know how to improve it, please let me know.

nfedyashev avatar Nov 01 '25 20:11 nfedyashev