Break up multiple changes into separate commits with git?

前端 未结 4 1242
鱼传尺愫
鱼传尺愫 2021-01-30 06:32

If I have made multiple sets of changes to a large file, is it possible to split those into separate commits using git?

4条回答
  •  滥情空心
    2021-01-30 07:20

    One more option which I constantly use is just because i forget about the patch option :):

    Say you have updated files: aaa.txt, bbb.txt, ccc.txt and you want to push the aaa.txt file in the first commit and then bbb.txt and ccc.txt in the second commit:

    step 1:
    --------------------
    git add aaa.txt
    git commit -m "Added first file"
    git stash
    git push
    
    step 2:
    --------------------
    git stash pop
    git add -A
    git commit -m "Added the rest of the modified data"
    git push
    

    Might be a little more verbose, but in my opinion I it gives a bit more control.

    Cheers!

提交回复
热议问题