Git - How to edit old (not previous) commit with some of the unstaged changes from current index (current state)?

前端 未结 4 1222
[愿得一人]
[愿得一人] 2020-12-17 01:19

I\'ve taken a look at these previous questions already:

  • Howto add a changed file to an older (not last) commit in Git
  • How do I edit a previous git comm
4条回答
  •  無奈伤痛
    2020-12-17 02:07

    `git stash`
    `git checkout `
    `git stash pop`
    `git add` (selectively--one file at a time)
    `git commit --amend`
    `git stash` (to re-stash all the changes you didn't commit)
    `git branch temp`
    `git checkout master`
    `git rebase temp -i`
    

    This will open a text editor with a list of commits--one commit per row. Delete the first row, which is the old commit that you want to replace. Save and close.

    `git branch -d temp` (to clean up the branch you created)
    

提交回复
热议问题