How can I split up a Git commit buried in history?

前端 未结 6 864
刺人心
刺人心 2020-11-28 17:15

I flubbed up my history and want to do some changes to it. Problem is, I have a commit with two unrelated changes, and this commit is surrounded by some other changes in my

6条回答
  •  盖世英雄少女心
    2020-11-28 17:35

    To split a commit and add the new commit before this one, and save the author date of , — the steps are following:

    1. Edit the commit before

      git rebase -i ^^
      

      NB: perhaps it will be also needed to edit as well.

    2. Cherry pick into the index

      git cherry-pick -n 
      
    3. Interactively reset unneeded changes from the index and reset the working tree

      git reset -p && git checkout-index -f -a
      

      As alternative, just stash unneeded changes interactively: git stash push -p -m "tmp other changes"

    4. Make other changes (if any) and create the new commit

      git commit -m "upd something" .
      

      Optionally, repeat the items 2-4 to add more intermediate commits.

    5. Continue rebasing

      git rebase --continue
      

提交回复
热议问题