tummychow / git-absorb

git commit --fixup, but automatic
https://crates.io/crates/git-absorb
BSD 3-Clause "New" or "Revised" License
4.64k stars 71 forks source link

Flag to absorb changes into the last time the whole file was changed #56

Closed rjmunro closed 1 year ago

rjmunro commented 2 years ago

Often I make a change like

 import a
+import b

 ...

 method {
-  use a here
+  use a+b here
 }

And I forget to include the import b when I commit the change. Could there be a way to ask git absorb to write a fixup that matched the last commit where a file changed in any way, rather than the last commit where it will cleanly merge? E.g. --whole-file-changes or something?

Obviously it should be used with care - there are often cases where there are 2 commits that change a file and git absorb will have no way to know which one introduced the requirement for the import, but it might be a useful feature.

tummychow commented 2 years ago

in your example, what parts of the change are already committed, and what parts are added to the index before you run git-absorb?

rjmunro commented 2 years ago

The above is the simulated output of git diff --cached - the - lines are previously committed, the + lines are in the index.

tummychow commented 2 years ago

ah thanks, now i see what you're asking for. you want a way to reconfigure commutation so that hunks only commute if they're in different files. yes, i think i'm open to this change, although i'm not sure it'll behave as well as you imagine. pr welcome - it would probably go immediately below here https://github.com/tummychow/git-absorb/blob/master/src/lib.rs#L160-L169 to bail out of the rest of the commute analysis if the paths do match

tummychow commented 1 year ago

-w introduced in #80