Add git support for vim using fugitive – diff
Leipzig
Add git support for vim using fugitive [1] #
Basics: add and checkout #
- index: last committed version of the
- working copy: file containing local changes (unstaged)
workflow #
- start: index and working copy are the same
- change: working copy has been changed
- add: after
git add <file>
index and working copy does match – changes has been staged
commands #
- run
:Gwrite
(similar to:Git add %
andgit add <file>
) on the working copy to apply changes to the index - run
:Gread
(similar to:Git checkout %
andgit checkout <file>
) on the working copy to reset changes to the index
Using add --patch #
- add patches from a changed file similar to
git add --patch
- in vim status split (
:Gstatus
) pressP
(shortcut in terminal:g add -p
) - does not add all the changes immediately
- goes through each change and asks whether you want to add it or not
- splits changes into hunks: displays a diff for each change (called hunk)
- Stage this hunk [y,n,q,a,d,j,J,g,/,s,e,?]?
y
yes stage this hunkn
no do not stage this hunkq
quit, do not stage this hunk or any of the remaining onesa
stage this hunk and all later hunks in the filed
do not stage this hunk or any of the later hunks in the filej
leave this hunk undecided, see next undecided hunkJ
leave this hunk undecided, see next hunkg
go to: select hunk to go to/
search for hunk matching the given regexs
split the current hunk into smaller hunkse
edit the current hunk manually?
print help
Using diff to execute add --patch #
- stage only some of the changes and keep others in the working copy (but not in the index)