How to suppress “Changes not staged for commit”?

How do I suppress the “Changes not staged for commit” output when committing? Note that:

  • I know I can do > /dev/null, but I’m hoping not to suppress other things.
  • I’m not talking about the commit message — I’m talking about what its printed to the terminal.

  • git commit to remote repository not working
  • Github Commit Syntax to Link a Pull Request/ Issue
  • Git push rejected after cloning
  • Git/Github allow collaborators but keep control
  • How to get a list of all Subversion commit author usernames?
  • Git pull results in extraneous “Merge branch” messages in commit log
  • Changes not reflected in PhpStorm after GIT checkout on remote machine
  • git stash: avoid “on <branch-name>” string in message
  • Jenkins Git Plugin: How to build specific tag?
  • Git won't let me rebase (untracked files would be overwritten). What should I do?
  • How can I use “git add --patch” in PhpStorm
  • Git merge ignore conflict from one branch?
  • One Solution collect form web for “How to suppress “Changes not staged for commit”?”

    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 ?

    Git Baby is a git and github fan, let's start git clone.