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
?
Asked
Active
Viewed 9,213 times
5

Romain Valeri
- 19,645
- 3
- 36
- 61

Paprika
- 402
- 5
- 18
3 Answers
10
(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
Finally, about fixing your .gitignore
, take a look at git check-ignore -v <path>
to know specifically which .gitignore
file ignores your path.

Romain Valeri
- 19,645
- 3
- 36
- 61
8
How to check which files staged
git status -s


spike 王建
- 1,556
- 5
- 14
-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

Basile Starynkevitch
- 223,805
- 18
- 296
- 547
-
5Be 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`. – torek Oct 27 '20 at 06:58