Is there a way/command on git to "distribute" the changes made to some files to the last commit that modified each file?
On many occasions I notice a small typo (mostly on comments: missing comma, closing a parenthesis, some small grammar error... ) in already committed files. I would like to fixup the last commit on each file to add the small fix. Is that possible without having to manually do a commit, run rebase --interactive
, move the commit up, mark it as a fixup
of the previous commit...
For instance: Let's say I have this situation:
Commit A: to add a new feature. 0xa1b2c3 2021/03/10 00:00:00
|-> last commit that modified file '/home/borrajax/projects/feature.py'
Commit B: to test the feature. 0xd4e5f6 2021/03/10 00:05:00
|-> last commit that modified file '/home/borrajax/projects/test_feature.py'
Commit C: something unrelated. 0x112233 2021/03/10 00:10:00
|-> doesn't alter 'feature.py' or 'test_feature.py'
Then, I fix some small typos in both feature.py
and test_feature.py
Is there a way of saying "add these small changes on file feature.py
to Commit A" and "add these small changes on file test_feature.py
to commit B" (keeping the commit order A -> B -> C)
What I currently do is:
- Adding the changes on
feature.py
into a commit like "Fixup Commit A" - Adding the changes on
test_feature.py
into a commit like "Fixup commit B" - Run a
rebase --interactive
- Move the "Fixup..." commits underneath the commits that I want to fix ("Fixup Commit A" under "Commit A: to add..." and "Fixup commit B" under "Commit B: to test...")
- Mark them as
fixups
in the--interactive
editor.
This is rather time consuming and pretty error prone.
I have read these other two S.O questions (Git distribute fixup commit to original commits and git: squash/fixup earlier commit) but I don't think the proposed solutions do quite what I'm looking for (maybe I'm wrong, and they do, though...)