RISHI KHANNA
RISHI KHANNA

Reputation: 374

How to remove unwanted files(100's in number) from git add list

I have around 30 files in the local repo that I needed to push to the server. But when I do git add . >> git commit -a "msg"... a large number of files also getting committed along with that. How do I remove those files?

What I have tried:

Adding all those wanted 30 files individually using git add and then committing. But still all those unwanted file added along. git reset HEAD~ >> git add . >> git commit. But issue still the same.

Upvotes: 1

Views: 625

Answers (2)

Romain Valeri
Romain Valeri

Reputation: 21918

The problem is the git commit -a you're doing afterwards. The -a parameter adds every change in the working directory to the index before committing.

Add each file separately, or do a git add . followed by some specific git reset HEAD -- <file>, either way's fine, but at the end do NOT use the -a parameter for your commit.

Reminder : git status lists files ready for commit and unstaged changes as two separate lists. So make sure you're fine with the list before your commit.

Upvotes: 1

Tim Biegeleisen
Tim Biegeleisen

Reputation: 521008

I recommend here that you just run git add only on the files which you actually want to add to the stage. One option which I use often is to just type git status from the Git bash, and then copy the list of files to an editor such as Notepad++. From there, it is easy enough to prepend a git add before each listed file name. Then, you only need to copy this list back to the bash, and all your files should be added.

Note that most of the time if you only have a handful of files to add, you may just type them out manually in the bash, and it is not too much of a headache.

Upvotes: 2

Related Questions