gitgit-addgit-rm

git add/rm files based on the type of change (of the files)


Is there a way to stage or unstage (git add / git rm) files only based on what was the type of modification?

Like :


Solution

  • Based on the other linked answer you can do (in bash)

    git diff --name-only --diff-filter=D | xargs git add
    

    to e.g. only add deleted files.

    You can use the other diff-filter options for modified, new, renamed files etc. And of course you can swap out git add for git reset etc.

    --diff-filter=[ACDMRTUXB*]

    Select only files that are

    • A Added
    • C Copied
    • D Deleted
    • M Modified
    • R Renamed
    • T have their type (mode) changed
    • U Unmerged
    • X Unknown
    • B have had their pairing Broken
    • * All-or-none

    Any combination of the filter characters may be used.