This shows how to partially stage a HUGE file, one piece at a time. git add -p
also does this, but sometimes doesn't show enough context and if the file is big enough, regex searching doesn't seem to always work.
- This requires Vim, with the Fugitive plugin installed (see reference links).
- Open the file in Vim, and type
:Gdiff
. The screen will split in two, with the left hand side showing the indexed version of the file (what will be committed), and the right hand side showing the current working copy. - Move the cursor to the right-side pane, and find the hunk you're interested in.
- With the cursor in the hunk, type
:diffput
. The hunk will disappear from the right hand side, and the left hand side will get a "+" in the status bar indicating unsaved changes. - Complete steps 2-3 until everything is staged.
- When done, move the cursor to the left pane and save it to stage the files.