Break a previous commit into multiple commits

前端 未结 14 2070
渐次进展
渐次进展 2020-12-20 13:09

Without creating a branch and doing a bunch of funky work on a new branch, is it possible to break a single commit into a few different commits after it\'s been committed to

14条回答
  •  旧巷少年郎
    2020-12-20 13:29

    If you have this:

    A - B <- mybranch
    

    Where you have committed some content in commit B:

    /modules/a/file1
    /modules/a/file2
    /modules/b/file3
    /modules/b/file4
    

    But you want to split B into C - D, and get this result:

    A - C - D <-mybranch
    

    You can divide the content like this for example (content from different directories in different commits)...

    Reset the branch back to the commit before the one to split:

    git checkout mybranch
    git reset --hard A
    

    Create first commit (C):

    git checkout B /modules/a
    git add -u
    git commit -m "content of /modules/a"
    

    Create second commit (D):

    git checkout B /modules/b
    git add -u
    git commit -m "content of /modules/b"
    

提交回复
热议问题