Commit only part of a file in Git

后端 未结 23 1981
一整个雨季
一整个雨季 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:42

    vim-gitgutter plugin can stage hunks without leaving vim editor using

    :GitGutterStageHunk
    

    Beside this, it provides other cool features like a diff sign column as in some modern IDEs

    If only part of hunk should be staged vim-fugitive

    :Gdiff
    

    allows visual range selection then :'<,'>diffput or :'<,'>diffget to stage/revert individual line changes.

提交回复
热议问题