Usually, we stage files before committing them:
$ git add vimrc
$ git commit -m 'Update vimrc'
[master f4efe1d] Update vimrc
1 file changed, 1 insertion(+)
However, we can also stage individual hunks in a file if we only want to commit part of the changes in that file:
$ git add --patch vimrc
diff --git a/vimrc b/vimrc
index c493cca..8a95218 100644
--- a/vimrc
+++ b/vimrc
@@ -56,7 +56,7 @@ endif
" Git
" -----------------------------------------------------------------------------
Plug 'tpope/vim-fugitive'
-Plug 'airblade/vim-gitgutter'
+" Plug 'airblade/vim-gitgutter'
Plug 'rhysd/conflict-marker.vim'
" -----------------------------------------------------------------------------
Stage this hunk [y,n,q,a,d,/,e,?]?
The git add --patch
or git add -p
command allows us to select hunks interactively for staging. You can type ?
during the process to print the help message to understand what each letter means:
y - stage this hunk
n - do not stage this hunk
q - quit; do not stage this hunk or any of the remaining ones
a - stage this hunk and all later hunks in the file
d - do not stage this hunk or any of the later hunks in the file
g - select a hunk to go to
/ - search for a hunk matching the given regex
j - leave this hunk undecided, see next undecided hunk
J - leave this hunk undecided, see next hunk
k - leave this hunk undecided, see previous undecided hunk
K - leave this hunk undecided, see previous hunk
s - split the current hunk into smaller hunks
e - manually edit the current hunk
? - print help
Tags: git