git-autofixup icon indicating copy to clipboard operation
git-autofixup copied to clipboard

Limit `git autofixup` to specified files and/or to staged changes

Open intelfx opened this issue 1 year ago • 3 comments

It would be nice if it was possible to limit git-autofixup to changes in specific files, e. g.:

git autofixup <base> -- /path/to/file /path/to/something/else

Alternatively (might be even more useful), accept something like

  • --staged to only operate on already staged changes (mirroring git stash --staged), and
  • --keep-index for the opposite (mirroring git stash --keep-index).

intelfx avatar Feb 25 '24 12:02 intelfx

On Sun, Feb 25, 2024 at 04:27:08AM -0800, Ivan Shapovalov wrote:

It would be nice if it was possible to limit git-autofixup to changes in specific files, e. g.:

git autofixup <base> -- /path/to/file /path/to/something/else

Good idea. It is probably doable to support arbitrary pathspecs by forwarding them to Git diff.

Alternatively (might be even more useful), accept something like

  • --staged to only operate on already staged changes (mirroring git stash --staged), and

that's already the default in the latest release - if you have anything staged, stage everything. It is indeed very useful.

  • --keep-index for the opposite (mirroring git stash --keep-index).

interesting, yeah. Would probably need to temporarily swap the index file but we already do that elsewhere.

krobelus avatar Feb 25 '24 15:02 krobelus

Regarding --keep-index: we could get conflicts when trying to restore the original index after doing git-autofixup for the working tree, right?

If I'm understanding correctly, it'd be roughly equivalent to this:

git checkout -b tmp
git commit -m 'saved index'
git checkout topic
git-autofixup
git checkout tmp
git rebase topic
git reset @^

But what if rebasing the saved index onto the changed topic branch fails?

torbiak avatar Feb 25 '24 22:02 torbiak