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,?]?
yyes stage this hunknno do not stage this hunkqquit, do not stage this hunk or any of the remaining onesastage this hunk and all later hunks in the fileddo not stage this hunk or any of the later hunks in the filejleave this hunk undecided, see next undecided hunkJleave this hunk undecided, see next hunkggo to: select hunk to go to/search for hunk matching the given regexssplit the current hunk into smaller hunkseedit 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)