Add git support for vim using fugitive – diff
Leipzig
Add git support for vim using fugitive [2: stage specific change]
- use
diff
to executeadd --patch
- stage only some of the unstaged changes
- keep others in the working copy
- update index file (index file needs to be saved)
Prerequisites
- change something in the working copy of a file
- open status split (
:Gstatus
) - get diff for certain file (move to file in status split, press
D
)
1. add hunk from working copy to index
- this could be either added (Example 1), removed lines (Example 2) or edited lines (Example 3)
- place cursor on the desired line
- divide hunks by using visual selection
:'<,'>diffput
(if necessary)
OPTION 1: select index (left)
add hunk by running :diffget
(shortcut: do
)
OPTION 2: select working copy (right)
add hunk by running :diffput
(shortcut: dp
)
2. save index file
by running :w
3. check status split
- status split should be realoaded automatically, if not type
:e
- if you have not added all changes, the file should appear twice
- only some of the changes have been staged
4. review staged changes
run :Git diff --cached %
(similar to git diff --cached <file>
) to list only staged changes for the file
5. commit and push changes
:Gcommit
and Gpush
Examples
Example 1: stage added lines
Example 2: stage removed lines
Example 3: stage edited lines