How can I easily fixup a past commit?

前端 未结 12 2317
执笔经年
执笔经年 2020-12-02 03:48

I just read amending a single file in a past commit in git but unfortunately the accepted solution \'reorders\' the commits, which is not what I want. So here\'s my question

12条回答
  •  旧巷少年郎
    2020-12-02 04:49

    I'd recommend https://github.com/tummychow/git-absorb:

    Elevator Pitch

    You have a feature branch with a few commits. Your teammate reviewed the branch and pointed out a few bugs. You have fixes for the bugs, but you don't want to shove them all into an opaque commit that says fixes, because you believe in atomic commits. Instead of manually finding commit SHAs for git commit --fixup, or running a manual interactive rebase, do this:

    • git add $FILES_YOU_FIXED

    • git absorb --and-rebase

    • or: git rebase -i --autosquash master

    git absorb will automatically identify which commits are safe to modify, and which indexed changes belong to each of those commits. It will then write fixup! commits for each of those changes. You can check its output manually if you don't trust it, and then fold the fixups into your feature branch with git's built-in autosquash functionality.

提交回复
热议问题