Issue
When I do git status
, I will see a list of files that are tracked and not tracked.
e.g.
On branch master
Your branch is up to date with 'origin/master'.
Changes not staged for commit:
(use "git add <file>..." to update what will be committed)
(use "git restore <file>..." to discard changes in working directory)
modified: ../TODO.md
Untracked files:
(use "git add <file>..." to include in what will be committed)
src/api/x.py
src/apps/x.py
src/schemas/x.py
../frontend/src/components/Notes/x.tsx
no changes added to commit (use "git add" and/or "git commit -a")
And if I wanted to see the content of the already tracked files I can do git diff
or git diff --staged
However though, I'd like an easy to way to see the full file contents of only all the untracked files that are not already gitignored (output format should be similar to what I'd see if I ran git diff
where it shows the (changed) contents in a list).
What is the best way to do this? Do I need to actually use a for loop in bash (ex) after parsing the git output, or is there a better way?
Solution
You can try
git ls-files --others -z | xargs -0 cat
This lists the untracked files (others) using null char delimiters to avoid problems with spaces and other special chars and sends it to xargs
which is also told to use null delimiters.
See git ls-files for other options.
Answered By - Diego Torres Milano Answer Checked By - Gilberto Lyons (WPSolving Admin)