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

Re: Best way to check for a "dirty" working tree?

From
Ramkumar Ramachandra <artagnon@gmail.com>
Date
Jun 12, 2011, 12:23 UTC
Message-ID
<BANLkTi=-HA1_47DvtGbVHx8twuEAxT8STQ@mail.gmail.com>
In-Reply-To
<4DF381BF.3050301@dirk.my1.cc>
Hi Dirk,
Dirk Süsserott writes:
Show 13 quoted lines
> A) if ! git diff-index --quiet HEAD -- foo.bar; then
>       dirty=1
>   fi
>
> and
>
> B) if ! git diff --quiet -- foo.bar; then
>       dirty=1
>   fi
>
> Both A) and B) work. But which one is better/faster/more reliable? Or is
> there a better solution? For my purpose, I cannot see a difference
> between diff and diff-index, except the syntax.

diff is a more porcelain'ish command, while diff-index is closer to the plumbing. Therefore, diff contains some extra argument parsing/ pretty printing code that your script doesn't utilize -- use diff-index. Also, look at the various scripts in git.git to see what they use; for example, require_clean_work_tree in git-sh-setup.sh.

-- Ram
Previous: Dirk SüsserottNext: Jonathan Nieder
Message 2 of 4 in “Best way to check for a "dirty" working tree?”
  1. Dirk SüsserottJun 11, 2011
  2. Ramkumar RamachandraJun 12, 2011
  3. Jonathan NiederJun 13, 2011
  4. Dirk SüsserottJun 14, 2011

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.