Is there a way to ignore dirty submodules when using git add --patch
?
I've set ignore = dirty
as explained here. This seems to only work with git status
and git diff
. I love git add -p
. Having to skip through 10 dirty submodules every time I want to add a small change frustrates me.
I haven't quite figured out git add -i
yet, but it looks like it handles dirty submodules the same way.
Having add silently ignore submodule updates seems, to quote Clint, tooooo dangerous.
I don't know how to do it with add --patch, but I can get pretty close with add --edit and a vim keymapping:
map <Leader>\x :%!sed '/^diff --git/\!{H;$\!d};x;1{$\!d;x};/\nindex[^\n]*160000\n/d'<CR>
while will map \\x
to eliminate all submodule update hunks. The \!
s in that are vim-specific bang escapes, strip those backslashes to use the sed elsewhere.
With Git 2.16.x/2.17, you won't even need a --ignore-submodules
option,
since "git add -p
" was taught to ignore local changes to submodules as
they do not interfere with the partial addition of regular changes
anyway.
See commit 12434ef (13 Jan 2018) by Nguyễn Thái Ngọc Duy (pclouds
).
(Merged by Junio C Hamano -- gitster
-- in commit e7e8077, 23 Jan 2018)
add--interactive: ignore submodule changes except HEAD
For 'add -i
' and 'add -p
', the only action we can take on a dirty
submodule entry is update the index with a new value from its HEAD
.
The content changes inside (from its own index, untracked files...) do not
matter, at least until 'git add -i
' learns about launching a new
interactive add session inside a submodule.
Ignore all other submodules changes except HEAD.
This reduces the number of entries the user has to check through in 'git add -i
', and the number of 'no
' they have to answer to 'git add -p
' when dirty submodules are present.