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

[PATCH] Show modified files in git-ls-files

From
BGBrian Gerst <bgerst@didntduck.org>
Date
Sep 2, 2005, 00:35 UTC
Message-ID
<43179E59.80106@didntduck.org>
Add -m/--modified to show files that have been modified wrt. the index.
M was already taken so the tag for modifified files is C (changed).

$ git-ls-files -m -t C Documentation/git-ls-files.txt C ls-files.c

Signed-off-by: Brian Gerst <bgerst@didntduck.org>
---
  Documentation/git-ls-files.txt |    4 ++++
  ls-files.c                     |   20 +++++++++++++++-----
  2 files changed, 19 insertions(+), 5 deletions(-)
Subject: [PATCH] Show modified files in git-ls-files
Add -m/--modified to show files that have been modified wrt. the index.
M was already taken so the tag for modifified files is C (changed).

$ git-ls-files -m -t C Documentation/git-ls-files.txt C ls-files.c

Signed-off-by: Brian Gerst <bgerst@didntduck.org>
---
 Documentation/git-ls-files.txt |    4 ++++
 ls-files.c                     |   20 +++++++++++++++-----
 2 files changed, 19 insertions(+), 5 deletions(-)
9de83ef7cce7ed5c1aa129cf2a81f8bce3aedb4f
diff --git a/Documentation/git-ls-files.txt b/Documentation/git-ls-files.txt
--- a/Documentation/git-ls-files.txt
+++ b/Documentation/git-ls-files.txt
@@ -33,6 +33,9 @@ OPTIONS
 -d|--deleted::
 	Show deleted files in the output
 
+-m|--modified::
+	Show modified files in the output
+
 -o|--others::
 	Show other files in the output
 
@@ -71,6 +74,7 @@ OPTIONS
 	H	cached
 	M	unmerged
 	R	removed/deleted
+	C	modifed (changed)
 	K	to be killed
 	?	other
 
diff --git a/ls-files.c b/ls-files.c
--- a/ls-files.c
+++ b/ls-files.c
@@ -17,6 +17,7 @@ static int show_ignored = 0;
 static int show_stage = 0;
 static int show_unmerged = 0;
 static int show_killed = 0;
+static int show_modified = 0;
 static int line_terminator = '\n';
 
 static int prefix_len = 0, prefix_offset = 0;
@@ -26,6 +27,7 @@ static const char **pathspec = NULL;
 static const char *tag_cached = "";
 static const char *tag_unmerged = "";
 static const char *tag_removed = "";
+static const char *tag_modified = "";
 static const char *tag_other = "";
 static const char *tag_killed = "";
 
@@ -443,15 +445,18 @@ static void show_files(void)
 			show_ce_entry(ce_stage(ce) ? tag_unmerged : tag_cached, ce);
 		}
 	}
-	if (show_deleted) {
+	if (show_deleted | show_modified) {
 		for (i = 0; i < active_nr; i++) {
 			struct cache_entry *ce = active_cache[i];
 			struct stat st;
+			int err;
 			if (excluded(ce->name) != show_ignored)
 				continue;
-			if (!lstat(ce->name, &st))
-				continue;
-			show_ce_entry(tag_removed, ce);
+			err = lstat(ce->name, &st);
+			if (show_deleted && err)
+				show_ce_entry(tag_removed, ce);
+			if (show_modified && ce_match_stat(ce, &st))
+				show_ce_entry(tag_modified, ce);
 		}
 	}
 }
@@ -547,6 +552,7 @@ int main(int argc, char **argv)
 			tag_cached = "H ";
 			tag_unmerged = "M ";
 			tag_removed = "R ";
+			tag_modified = "C ";
 			tag_other = "? ";
 			tag_killed = "K ";
 			continue;
@@ -559,6 +565,10 @@ int main(int argc, char **argv)
 			show_deleted = 1;
 			continue;
 		}
+		if (!strcmp(arg, "-m") || !strcmp(arg, "--modified")) {
+			show_modified = 1;
+			continue;
+		}
 		if (!strcmp(arg, "-o") || !strcmp(arg, "--others")) {
 			show_others = 1;
 			continue;
@@ -630,7 +640,7 @@ int main(int argc, char **argv)
 	}
 
 	/* With no flags, we default to showing the cached files */
-	if (!(show_stage | show_deleted | show_others | show_unmerged | show_killed))
+	if (!(show_stage | show_deleted | show_others | show_unmerged | show_killed | show_modified))
 		show_cached = 1;
 
 	read_cache();
Next: Catalin Marinas
Message 1 of 4 in “Show modified files in git-ls-files”
  1. Show modified files in git-ls-filesBrian Gerst, Sep 2, 2005
  2. Catalin MarinasSep 2, 2005
  3. Junio C HamanoSep 2, 2005
  4. Brian GerstSep 2, 2005

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.