Search code examples
gitdiffgit-diff

Remove part of the content of a file from the last commit and apply it to the working tree


So, I've accidentally made the commit in which a few of the changes (all of them are in the same file) had to be made in the next commit. I want to delete parts of the changes made in the last commit from it and apply them to the working tree (so I can use them for a new commit). How can I do that?


Solution

  • git reset -p @^
    git commit --amend
    git commit -a
    

    That's "choose changes made by the last commit to un-stage, replace the last commit with a new one (with the staged content that has those changes removed), then make a new commit from the current content in the work tree."