How to retrieve all non deleted file form Repo using git
Solution 1:
Read the documentation and set up the desired flags.
https://git-scm.com/docs/git-ls-files
You are looking for this:
git ls-files -o --exclude-standard
-c / - -cached
Show cached files in the output (default)
-d / --deleted
Show deleted files in the output
-m / --modified
Show modified files in the output
-o / --others
Show other (i.e. untracked) files in the output
-i / --ignored
Show only ignored files in the output. When showing files in the index, print only those matched by an exclude pattern. When showing "other" files, show only those matched by an exclude pattern.
Another option is to use the git diff
with the git-filter
git diff --name-only --diff-filter=A --cached
--diff-filter=[(A|C|D|M|R|T|U|X|B)…[*]]
Select only files that are Added (A) Copied (C) Deleted (D) Modified (M) Renamed (R)
Solution 2:
This script should print all modified and untracked files, then exclude removed if thus exist.
git ls-files -o -m --exclude-standard | grep -vE "^$(git ls-files -d | paste -sd "|" -)$"
Description:
-
git ls-files --other
- shows other (i.e. untracked) files in the output -
git ls-files --modified
- shows modified files in the output -
git ls-files
- shows deleted files in the output -
git ls-files --exclude-standard
- adds the standard Git exclusions: .git/info/exclude, .gitignore in each directory, and the user's global exclusion file. -
grep -vE PATTERN
- excludes from the output in accordance with a given pattern -
paste -sd "|" -
concatenates the output by lines with '|' symbol