How do I see git added files?
Asked Answered
A

3

6

Sometimes I run git add . and big files that weren't supposed to get added are added. How can I see which files were added without commiting? And how to 'un-add' those files or all files at once so I can fix the .gitignore?

Anarchy answered 27/10, 2020 at 6:48 Comment(0)
R
11

(Disclaimer : none of the commands below modifies your changes in files, all this is about what's staged or not)
How to...

...display the full list of what's staged at this point. (doc for diff --staged)
git diff --staged --name-only

..."un-add" (unstage) one file
git reset -- path/to/file

...or similarly, unstage a directory with everything in it
git reset -- path/to/dir/

...unstage everything (example in the doc)
git reset

...and last but not least, the "unstage wizard"! (interactive unstaging, which goes chunk by chunk like it does for git add -p)
git reset -p


Finally, about fixing your .gitignore, take a look at git check-ignore -v <path> to know specifically which .gitignore file ignores your path.

Regazzi answered 27/10, 2020 at 6:49 Comment(0)
U
9

How to check which files staged

git status -s

Files with a green M letter prefix indicate that they have been cached, And red means it is still in the workspace, not cached.
Underhand answered 27/10, 2020 at 7:9 Comment(0)
W
-2

And how to 'un-add' those files

Use git rm your-file. For details, see the documentation of git or try git rm --help

Wallah answered 27/10, 2020 at 6:52 Comment(1)
Be careful: git rm removes both the index (aka staging area) copy of the file and the work-tree copy. Typically one might like to keep the work-tree copy, for which one must use git rm --cached.Goidelic

© 2022 - 2024 — McMap. All rights reserved.