Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can git status be made to mention the stash?

Tags:

git

I tend to forget that I had stashed some changes. I'd like to see stash mentioned in git status output, when the stash is not empty. Is there a way to get git status do this?

like image 503
Irfy Avatar asked May 23 '16 19:05

Irfy


People also ask

What information does git status show?

The git status command displays the state of the working directory and the staging area. It lets you see which changes have been staged, which haven't, and which files aren't being tracked by Git. Status output does not show you any information regarding the committed project history.

How do I check my git stash status?

Git Stash List. The Git stash list command will pull up a list of your repository's stashes. Git will display all of your stashes and a corresponding stash index. Now, if you wish to view the contents of a specific stash, you can run the Git stash show command followed by stash@ and the desired index.

Can you label a git stash?

To better identify a git stash, add a custom name or message by using the option -m followed by the message when creating a stash. We can quickly verify the message was added to the stash by listing the git stashes using the git stash list command.

How do I stage stash changes in git?

Stage all your files that you need to stash. Run git stash --keep-index . This command will create a stash with ALL of your changes (staged and unstaged), but will leave the staged changes in your working directory (still in state staged). Now your "good stash" has ONLY staged files.


2 Answers

This is now a built-in option in git status, so you can just do:

[status]
  showStash = true

If you're not comfortable editing your git config file, you can do

git config --global status.showStash true
like image 168
gib Avatar answered Sep 20 '22 19:09

gib


As far as I can see, there is no built-in option to do this, but there are a couple of ways of achieving the desired effect.

git-prompt.sh

Source the git-prompt.sh script as described in its documentation, and set the GIT_PS1_SHOWSTASHSTATE variable, e.g. in ~/.bashrc:

. ~/.bash/git-prompt.sh
GIT_PS1_SHOWSTASHSTATE=1
PROMPT_COMMAND='__git_ps1 "\u@\h:\w" "\\\$ "'

Now your command prompt will show a dollar sign next to the branch name in the git prompt:

user@host:~/repo (master$)$

git alias

You can make an alias for the desired functionality, although the alias cannot be status, it must be different from any built-in command:

git config --global alias.vstatus '!git status; git stash list'

This will set up a global alias vstatus (verbose status) that will simply run git status and git stash list back to back.

shell alias

One can always make a shell alias to intercept git subcommand invocation, as git aliases for built-in commands are ignored. In .bash_aliases:

git () {
    command git "$@" || return # preserve $?
    [[ $1 = status ]] && command git stash list
}

This will simply always run git stash list after every git status. When the stash is empty, nothing will be output.

like image 45
Irfy Avatar answered Sep 22 '22 19:09

Irfy