mirror of
https://github.com/jbranchaud/til
synced 2026-01-03 15:18:01 +00:00
Add List Untracked Files For Scripting as a git til
This commit is contained in:
@@ -10,7 +10,7 @@ pairing with smart people at Hashrocket.
|
|||||||
|
|
||||||
For a steady stream of TILs, [sign up for my newsletter](https://tinyletter.com/jbranchaud).
|
For a steady stream of TILs, [sign up for my newsletter](https://tinyletter.com/jbranchaud).
|
||||||
|
|
||||||
_1072 TILs and counting..._
|
_1073 TILs and counting..._
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
@@ -260,6 +260,7 @@ _1072 TILs and counting..._
|
|||||||
- [List Just The Files Involved In A Commit](git/list-just-the-files-involved-in-a-commit.md)
|
- [List Just The Files Involved In A Commit](git/list-just-the-files-involved-in-a-commit.md)
|
||||||
- [List Most Git Commands](git/list-most-git-commands.md)
|
- [List Most Git Commands](git/list-most-git-commands.md)
|
||||||
- [List Untracked Files](git/list-untracked-files.md)
|
- [List Untracked Files](git/list-untracked-files.md)
|
||||||
|
- [List Untracked Files For Scripting](git/list-untracked-files-for-scripting.md)
|
||||||
- [Move The Latest Commit To A New Branch](git/move-the-latest-commit-to-a-new-branch.md)
|
- [Move The Latest Commit To A New Branch](git/move-the-latest-commit-to-a-new-branch.md)
|
||||||
- [Pick Specific Changes To Stash](git/pick-specific-changes-to-stash.md)
|
- [Pick Specific Changes To Stash](git/pick-specific-changes-to-stash.md)
|
||||||
- [Pulling In Changes During An Interactive Rebase](git/pulling-in-changes-during-an-interactive-rebase.md)
|
- [Pulling In Changes During An Interactive Rebase](git/pulling-in-changes-during-an-interactive-rebase.md)
|
||||||
|
|||||||
29
git/list-untracked-files-for-scripting.md
Normal file
29
git/list-untracked-files-for-scripting.md
Normal file
@@ -0,0 +1,29 @@
|
|||||||
|
# List Untracked Files For Scripting
|
||||||
|
|
||||||
|
You'll generally run `git status` to get an overview of the index and working
|
||||||
|
tree of a git project. This is a _porcelain_ command meant for a Git end-user.
|
||||||
|
If you want to do some scripting, you'll want a _plumbing_ command like
|
||||||
|
`ls_files`.
|
||||||
|
|
||||||
|
The `git ls-files` command will
|
||||||
|
|
||||||
|
> Show information about files in the index and the working tree
|
||||||
|
|
||||||
|
This command can be used to list all untracked files in the working tree with
|
||||||
|
two flags.
|
||||||
|
|
||||||
|
1. The `--others` flag will show untracked files in the output
|
||||||
|
2. The `--exclude-standard` will use the standard ignore files like
|
||||||
|
`.gitignore` and `.git/info/exclude`.
|
||||||
|
|
||||||
|
Put it all together and you've got:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
$ git ls-files --others --exclude-standard
|
||||||
|
```
|
||||||
|
|
||||||
|
In [Make One-Line Commands Interactive with
|
||||||
|
fzf](https://www.youtube.com/watch?v=wf5eXdwfVws), I show how to use this with
|
||||||
|
`fzf` to interactively remove untracked files that are no longer wanted.
|
||||||
|
|
||||||
|
[source](https://stackoverflow.com/a/3801554/535590)
|
||||||
Reference in New Issue
Block a user