Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to make git status show only staged files

Tags:

git

git-status

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 good alternative?

The file list will be piped to php -l (PHP lint syntax checker).

Solution: the complete command

git diff --name-only --cached | xargs -l php -l 
like image 813
Ward Bekker Avatar asked Dec 24 '10 07:12

Ward Bekker


People also ask

How do I see staged files in git?

If your changes are already staged, then there's no difference to show. But there's a command line option that will show you staged changes if you specify it: git diff --staged . With the --staged option, git diff will compare your staged changes against the previous commit.

Does git status show untracked files?

git status has the untracked-files switch where we select which files to see each time we execute git status . The mode parameter is used to specify the handling of untracked files. It is optional: it defaults to all, and if specified, it must be stuck to the option (e.g. -uno, but not -u no).

How do I ignore a staged file in git?

Simply move the files to a folder outside of git, then do "git add .", "git commit". (This removed the files) then add the gitignore, referencing the files/folders, commit again to add the gitignore file to git, then copy/move back in the folders, and they should be ignored.


2 Answers

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

like image 77
Ben Jackson Avatar answered Oct 01 '22 11:10

Ben Jackson


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

like image 41
coffman21 Avatar answered Oct 01 '22 10:10

coffman21