How to make git status show only staged files

后端 未结 4 593
野趣味
野趣味 2020-11-30 23:56

I would like to get a list of only the staged filenames. I can\'t find the equivalent flag for --name-only for the git status command. What is a go

相关标签:
4条回答
  • 2020-12-01 00:17

    Use git diff --name-only (with --cached to get the staged files)

    0 讨论(0)
  • 2020-12-01 00:25

    to view staged files with code changes

    git diff --staged   
    

    or using --cached which is synonym for --staged

    git diff --cached
    

    or to view only file names without code changes

    git diff --staged --name-only  
    

    git-diff manual

    0 讨论(0)
  • 2020-12-01 00:28

    The accepted answer won't let you know what kind of changes were there.

    Yes, If you are not syntax checker but an ordinary person with a repository full of unstaged files, and you still want to know what will happen to staged files - there is another command:

    git status --short | grep '^[MARCD]'
    

    which leads to something like:

    M  dir/modified_file
    A  dir/new_file
    R  dir/renamed -> dir/renamed_to
    C  dir/copied_file
    D  dir/deleted_file
    

    Obviously, this files were staged, and after git commit:
    deleted_file will be deleted,
    new_file will be added,
    renamed_file will become a renamed_to.

    Here is an explanation of short-format output: https://git-scm.com/docs/git-status#_short_format

    0 讨论(0)
  • 2020-12-01 00:33

    Inspired by @coffman21's answer I have setup the following alias in my .zshrc

    alias gst="git status"
    alias gst-staged="git status --short | grep '^\w.'"
    alias gst-unstaged="git status  --short | grep '^\W.'"
    alias gst-unstaged-tracked="git status  --short | grep '^\s.'"
    alias gst-untracked="git status --short | grep '^??'"
    

    It might be of use to anyone else. So adding it to the stack of answers.

    0 讨论(0)
提交回复
热议问题