Break up multiple changes into separate commits with git?

前端 未结 4 1232
鱼传尺愫
鱼传尺愫 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:15

    Williams answer is perfectly valid. But sometimes it is easier to do things by hand. For example if you accidentally updated some third-party library with a lot of files before committing the changes you previously made. With git add -p (same as --patch) you would need to walk through all of this files. So in this case it is much more convenient to just stage the file you want to commit and do a second commit with all of the other changes:

    > git add /path/to/your/file.txt
    > git commit -m "my commit message"
    [master a0c5ea6] my commit message
    1 file changed, 2 insertions(+), 1 deletion(-)
    > git add --all
    > git commit -m "updated library xyz"
    

提交回复
热议问题