With git I would like to add (almost) all the modified files, in practice those marked with the letter M in VScode, but I would like to add exceptions, that is, not to consider one or two files.
Is there a generic way to say to add all the changes except one or two files?
Asked
Active
Viewed 862 times
1

Memmo
- 298
- 3
- 8
- 31
-
Yes, add each and every file you actually want to commit. – fredrik Jan 10 '20 at 09:25
-
1https://stackoverflow.com/a/51914162/10155936 – Saurabh P Bhandari Jan 10 '20 at 09:31
-
what if there are too many files then it becomes difficult to add individual files then [this](https://stackoverflow.com/a/59679018/12668430) will be helpful – Radha Manohar Jan 10 '20 at 09:44
2 Answers
2
You might be better off adding everything then unstaging the ones you don't want :
git add -u
git reset -- path/to/file1 path/to/file2

Romain Valeri
- 19,645
- 3
- 36
- 61
-
-
generally `-u` is used to detect changed files. Let say you have changed a file and created a new file. git will only recognize the file change but not the new file. by giving `-u` it recognizes new file entries too – Radha Manohar Jan 10 '20 at 09:42
-
@Memmo git add . is to add all files including those which are not been tracked, git add -u is to add all the files which are tracked. – Amitkumar Karnik Jan 10 '20 at 09:42
-
-
1@Memmo I didn't get that you wanted to (re)add each file, I took it as "every modified file", but yes, `-u` is the right tool to update every known path. – Romain Valeri Jan 10 '20 at 09:50
0
Add the two/three files to the .gitignore
and push all the changes. By default git ignores those two files, so that exemptions are ignored. After the push
remove the files from .gitignore
. This hack will definitely work.

Paolo
- 21,270
- 6
- 38
- 69

Radha Manohar
- 409
- 3
- 15