Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4006644
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T08:32:21+00:00 2026-05-20T08:32:21+00:00

The goal is to get an unambiguous status that can be evaluated in a

  • 0

The goal is to get an unambiguous status that can be evaluated in a shell command.

I tried git status but it always returns 0, even if there are items to commit.

git status
echo $?  #this is always 0

I have an idea but I think it is rather a bad idea.

if [ git status | grep -i -c "[a-z]"> 2 ];
then
 code for change...
else
  code for nothing change...
fi

any other way?


update with following solve, see Mark Longair’s post

I tried this but it causes a problem.

if [ -z $(git status --porcelain) ];
then
    echo "IT IS CLEAN"
else
    echo "PLEASE COMMIT YOUR CHANGE FIRST!!!"
    echo git status
fi

I get the following error [: ??: binary operator expected

now, I am looking at the man and try the git diff.

===================code for my hope, and hope better answer======================

#if [ `git status | grep -i -c "$"` -lt 3 ];
# change to below code,although the above code is simple, but I think it is not strict logical
if [ `git diff --cached --exit-code HEAD^ > /dev/null && (git ls-files --other --exclude-standard --directory | grep -c -v '/$')` ];
then
        echo "PLEASE COMMIT YOUR CHANGE FIRST!!!"
    exit 1

else
    exit 0
fi
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-20T08:32:22+00:00Added an answer on May 20, 2026 at 8:32 am

    An alternative to testing whether the output of git status --porcelain is empty is to test each condition you care about separately. One might not always care, for example, if there are untracked files in the output of git status.

    For example, to see if there are any local unstaged changes, you can look at the return code of:

    git diff --exit-code
    

    To check if there are any changes that are staged but not committed, you can use the return code of:

    git diff --cached --exit-code
    

    Finally, if you want to know about whether there are any untracked files in your working tree that aren’t ignored, you can test whether the output of the following command is empty:

    git ls-files --other --exclude-standard --directory
    

    Update: You ask below whether you can change that command to exclude the directories in the output. You can exclude empty directories by adding --no-empty-directory, but to exclude all directories in that output I think you’ll have to filter the output, such as with:

    git ls-files --other --exclude-standard --directory | egrep -v '/$'
    

    The -v to egrep means to only output lines that don’t match the pattern, and the pattern matches any line that ends with a /.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

How do i do that? Actually my main goal is to get which checkbox
Goal is to make a dialog that appears on menu_key pressed, but it keeps
I've tried the various suggestions from other posts and still can't seem to get
I have problem that im trying to get solve for like week. My goal
my site page's goal is to get information from a fairly complex (but concise)
My goal is to get a list of eBay categories programmatically. It appears that
l = ['1','2','3'] goal = ['<li>1</li>','<li>2</li>'] How can I get goal from l ?
Goal : Get a screenshot of a map with overlays(MKOverlayView) as well as the
My goal is to get a Time instance from a DateTime instance This has
My goal is to get various SEO-relevant information for various sites. Basically all the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.