Enhancement: Only commit staged files if files have been staged.
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
I want this too!
I want this too!
I have added new PR with command /scommit for exactly this: https://github.com/Aider-AI/aider/pull/2763
instead of scommit, it would be more ergonomic if commit just behaved like git commit and only considered staged files by default
instead of
scommit, it would be more ergonomic ifcommitjust behaved likegit commitand only considered staged files by default
...or all modified files if none are staged.
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/
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:
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
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.
Meanwhile I have found a pretty simple workflow:
- stash worktree (stashes unstaged changes) with
git stash push --keep-index --include-untracked -m "WIP unstaged for commit"Ofcause git aliased asgit stash-wip - 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".
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.