git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: Suggestion: git status --untracked

From
Jeff King <peff@peff.net>
Date
Feb 11, 2008, 10:23 UTC
Message-ID
<20080211102359.GA5916@coredump.intra.peff.net>
In-Reply-To
<b77c1dce0802110146o708e26a7lef56683f6b823365@mail.gmail.com>
On Mon, Feb 11, 2008 at 10:46:25AM +0100, Rafael Garcia-Suarez wrote:
> I find myself wanting sometimes to filter out the output of
> git-status, to feed it to another command (for example, git-add, or
> rm, or cat >> .gitignore). However it's not currently very easy to
> parse in a one-liner.
Here's a one-liner:
  git status | sed -ne '/^# Untracked/,${s/#\t//p}'

Unfortunately it is both specific to GNU sed as well as horribly unreadable.

> I'm suggesting to add options to control this behaviour. My suggestion
> would be (for a start) to add an option --untracked that will list all
> untracked files on stdout, without a leading "#\t", and without
> listing the added / modified / removed files.

The problem you are running into is that "git status" has a specific purpose: generating the commit message template. Fortunately, it is built on top of plumbing that is much easier to parse:

  git ls-files -o --exclude-standard

should produce the results you want. It even has a '-z' option to do things safely in the face of filenames with newlines, and can limit itself to partial paths.

-Peff
Previous: Rafael Garcia-SuarezNext: Jakub Narebski
Message 4 of 5 in “Suggestion: git status --untracked”
  1. Rafael Garcia-SuarezFeb 11, 2008
  2. Matthieu MoyFeb 11, 2008
  3. Rafael Garcia-SuarezFeb 11, 2008
  4. Jeff KingFeb 11, 2008
  5. Jakub NarebskiFeb 11, 2008

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.