How can I easily fixup a past commit?

前端 未结 12 2335
执笔经年
执笔经年 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:34

    I'm not aware of an automated way, but here's a solution that might by easier to human-botize:

    git stash
    # write the patch
    git add -p 
    git commit -m"whatever"   # message doesn't matter, will be replaced via 'fixup'
    git rebase -i ~1
    # now cut&paste the "whatever" line from the bottom to the second line
    # (i.e. below ) and change its 'pick' into 'fixup'
    # -> the fix commit will be merged into the  without changing the
    # commit message
    git stash pop
    

提交回复
热议问题