There's a workflow I tend to do fairly often and I wonder if Magit could help me. I've made a bunch of git commits on a branch, I haven't pushed them yet, and I notice a small mistake in my unpushed work which I'd like to fix by amending the commit that introduced it rather than making a new commit.

I can use blame to find the offending commit, do an interactive rebase and edit the offending commit. But that's not always convenient. For example, if I run a validation process and find multiple minor issues, then I need to fix multiple commits. What I do is to make all the fixes, commit them separately, and then do an interactive rebase to apply them as fixups. (For the sake of this question, assume that this won't lead to a conflict.) So my workflow is, for each fix:

  1. Stage the fix.
  2. Use blame to locate the commit that needs to be amended. I do this from vc-annotate, because it shows me the commit ID for each line in a very handy way.
  3. Commit the fix with the message fixup 1234567 where 1234567 is the commit ID.

  4. Then I do an interactive rebase to apply the fixup NNNNNNN as fixups to their respective NNNNNNN.

Can Magit help me with step 2? I'm in the *magit* buffer, looking at a deleted or unchanged line, and I want the blame information for that line, i.e. the commit ID that introduced that line.

modified   myfile
@@ -1,3 +1,3
-bat               ←My cursor is here. What commit introduced `bat`?

1 Answer 1


Since I have started using git autofixup I have saved a lot of time determining "the commit where I should have done that in the first place".

Magit wraps that as magit-commit-absorb, but this command isn't available from the committing popup by default yet.

Here's a typical workflow.

  1. Do not stage your changes. (git autofixup operates on all unstaged changes and refuses to do anything if there are staged changes. I think it should instead operate on the staged changes and ignore the unstaged ones. Maybe in a future version.)

  2. Type c x. (After having added that binding for magit-commit-absorb.)

  3. Briefly look at the generated fixup commits.

  4. r f to join the fixup commits with their targets.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.