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

[PATCH 1/2] Suggest use of "git add file1 file2" when there is nothing to commit.

From
Shawn O. Pearce <spearce@spearce.org>
Date
Dec 16, 2006, 02:53 UTC
Message-ID
<20061216025309.GA19955@spearce.org>

If a user modifies files and runs 'git commit' (without the very useful -a option) and they have not yet updated the index they are probably coming from another SCM-like tool which would perform the same as 'git commit -a' in this case. Showing the user their current status and a final line of "nothing to commit" is not very reassuring, as the user might believe that Git did not recognize their files were modified.

Instead we can suggest as part of the 'nothing to commit' message that the user invoke 'git add' to add files to their next commit.

Suggested by Andy Parkins' Git 'niggles' list (<200612132237.10051.andyparkins@gmail.com>).

Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
---
 git-commit.sh |    2 +-
 wt-status.c   |   11 ++++++-----
 2 files changed, 7 insertions(+), 6 deletions(-)
diff --git a/git-commit.sh b/git-commit.sh
index 05828bb..2672def 100755
--- a/git-commit.sh
+++ b/git-commit.sh
@@ -515,7 +515,7 @@ then
 	current="$(git-rev-parse --verify HEAD)"
 else
 	if [ -z "$(git-ls-files)" ]; then
-		echo >&2 Nothing to commit
+		echo >&2 'nothing to commit (use "git add file1 file2" to include for commit)'
 		exit 1
 	fi
 	PARENTS=""
diff --git a/wt-status.c b/wt-status.c
index 6e9414d..2173d4f 100644
--- a/wt-status.c
+++ b/wt-status.c
@@ -15,6 +15,7 @@ static char wt_status_colors[][COLOR_MAXLEN] = {
 	"\033[31m", /* WT_STATUS_CHANGED: red */
 	"\033[31m", /* WT_STATUS_UNTRACKED: red */
 };
+static const char* use_add_msg = "use \"git add file1 file2\" to include for commit";
 
 static int parse_status_slot(const char *var, int offset)
 {
@@ -162,8 +163,7 @@ static void wt_status_print_changed_cb(struct diff_queue_struct *q,
 {
 	int i;
 	if (q->nr)
-		wt_status_print_header("Changed but not updated",
-				"use git-add on files to include for commit");
+		wt_status_print_header("Changed but not updated", use_add_msg);
 	for (i = 0; i < q->nr; i++)
 		wt_status_print_filepair(WT_STATUS_CHANGED, q->queue[i]);
 	if (q->nr)
@@ -249,8 +249,7 @@ static void wt_status_print_untracked(const struct wt_status *s)
 				continue;
 		}
 		if (!shown_header) {
-			wt_status_print_header("Untracked files",
-				"use \"git add\" to add to commit");
+			wt_status_print_header("Untracked files", use_add_msg);
 			shown_header = 1;
 		}
 		color_printf(color(WT_STATUS_HEADER), "#\t");
@@ -292,7 +291,9 @@ void wt_status_print(struct wt_status *s)
 	if (s->verbose && !s->is_initial)
 		wt_status_print_verbose(s);
 	if (!s->commitable)
-		printf("%s\n", s->amend ? "# No changes" : "nothing to commit");
+		printf("%s (%s)\n",
+			s->amend ? "# No changes" : "nothing to commit",
+			use_add_msg);
 }
 
 int git_status_config(const char *k, const char *v)
-- 
1.4.4.2.g053a
Next: Michael Loeffler
Message 1 of 26 in “Suggest use of "git add file1 file2" when there is nothing to commit.”
  1. 1/2 Suggest use of "git add file1 file2" when there is nothing to commit.Shawn O. Pearce, Dec 16, 2006
  2. Michael LoefflerJan 5, 2007
  3. Junio C HamanoJan 5, 2007
  4. Junio C HamanoJan 6, 2007
  5. Juergen RuehleJan 6, 2007
  6. Junio C HamanoJan 6, 2007
  7. Juergen RuehleJan 6, 2007
  8. Junio C HamanoJan 8, 2007
  9. Juergen RuehleJan 8, 2007
  10. Junio C HamanoJan 8, 2007
  11. Provide better feedback for the untracked only case in status outputJuergen Ruehle, Jan 10, 2007
  12. Juergen RuehleJan 10, 2007
  13. Juergen RuehleJan 10, 2007
  14. Junio C HamanoJan 10, 2007
  15. Juergen RuehleJan 10, 2007
  16. Quick hack to avoid double qp encodingJuergen Ruehle, Jan 10, 2007
  17. Juergen RuehleJan 10, 2007
  18. Junio C HamanoJan 10, 2007
  19. Michael LoefflerJan 10, 2007
  20. Juergen RuehleJan 10, 2007
  21. Provide better feedback for the untracked only case in status outputJuergen Ruehle, Jan 10, 2007
  22. Jeff KingJan 10, 2007
  23. Juergen RuehleJan 11, 2007
  24. Juergen RuehleJan 6, 2007
  25. Michael LoefflerJan 8, 2007
  26. Juergen RuehleJan 9, 2007

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.