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

  • Home
  • SEARCH
  • 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 7416313
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T07:28:16+00:00 2026-05-29T07:28:16+00:00

I am writing a script which will do this: #!/bin/bash mysqldump -u user -p

  • 0

I am writing a script which will do this:

#!/bin/bash
mysqldump -u user -p database > db_file
git add db_file
git commit -m 'db_file updated by script'

However, what if the index is dirty when I run this script? That is, what if I already git added files that I want to not have automatically committed when this script runs? I could do this:

#!/bin/bash
mysqldump -u user -p database > db_file
git stash
git add db_file
git commit -m 'db_file updated by script'
git stash apply

But now the problem is that if the index and working tree is not dirty, then git stash doesn’t add anything to the stash list, but git stash apply will incorrectly apply whatever is on top of the stash and discard the history of that stash.

How can I make a bash conditional based on if the index is dirty?

  • 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-29T07:28:18+00:00Added an answer on May 29, 2026 at 7:28 am

    git diff --cached --quiet

    Previous answer:

    git diff --cached will show exactly what I want to know. The only problem is that the return value is true no matter what, so it’s hard to make a conditional off of that. If there is not better answer, then I can dump the output to a file and make a condition on if the file is empty or not. But that sounds painfully hack-ish. Surely there is a better way.

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

Sidebar

Related Questions

I am writing a script which will add a new project in the repository,
I'm writing a bash script to modify a config file which contains a bunch
I am writing a script which will list 25 items of all 12 categories.
I'm writing a script which will have to work on directories which are modified
I am writing a Tcl script which will be used on an embedded device.
Hi I am writing a small jQuery script which will toggle a hidden Top-Panel
I am writing some expect commands in bash. Script: #!/bin/bash set timeout -1 expect
I am writing a script which will display a stock chart as ASCII art
I'm writing a php script which will enable people to change the theme of
I'm trying to write a bash script which will, given the name of a

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.