Reputation: 210352
How do I suppress the "Changes not staged for commit" output when committing? Note that:
> /dev/null
, but I'm hoping not to suppress other things.Upvotes: 4
Views: 211
Reputation: 1335
After a bit of digging in the git.git codebase, I am afraid you should be designing a way to ignore those lines in your script.
During a commit, if you don't use --allow-empty
, git will go through that code:
if (!commitable && whence != FROM_MERGE && !allow_empty &&
!(amend && is_a_merge(current_head))) {
s->display_comment_prefix = old_display_comment_prefix;
run_status(stdout, index_file, prefix, 0, s);
...
return 0;
}
And run_status
does the following thing:
switch (status_format) {
case STATUS_FORMAT_SHORT:
wt_shortstatus_print(s);
break;
case STATUS_FORMAT_PORCELAIN:
wt_porcelain_print(s);
break;
case STATUS_FORMAT_UNSPECIFIED:
die("BUG: finalize_deferred_config() should have been called");
break;
case STATUS_FORMAT_NONE:
case STATUS_FORMAT_LONG:
wt_status_print(s);
break;
}
}
STATUS_FORMAT_PORCELAIN
(use --porcelain
) and STATUS_FORMAT_SHORT
(git config status.short true
) will result in the same minified output:
M bla.txt
and STATUS_FORMAT_LONG
(AND STATUS_FORMAT_NONE
, not sure why ?), will result in the usual output:
Changes not staged for commit:
modified: bla.txt
That said, let's not despair, this is software we're talking about, there is always a way around the problem (I still need to completely test this though ;) )
You could use --allow-empty
to get pass that code branch and create an empty commit. Then, you chain that with a post-commit
hook that checks whether the latest commit is empty, if it is, the hook runs git reset --hard HEAD~1
and you could be good to go ?
Upvotes: 1