Commit only part of a file in Git

后端 未结 23 2322
一整个雨季
一整个雨季 2020-11-22 05:50

When I make changes to a file in Git, how can I commit only some of the changes?

For example, how could I commit only 15 lines out of 30 lines that have been changed

23条回答
  •  甜味超标
    2020-11-22 06:47

    If you are using vim, you may want to try the excellent plugin called fugitive.

    You can see the diff of a file between working copy and index with :Gdiff, and then add lines or hunks to the index using classic vim diff commands like dp. Save the modifications in the index and commit with :Gcommit, and you're done.

    Very good introductory screencasts here (see esp. part 2).

提交回复
热议问题