1

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?

Memmo
  • 298
  • 3
  • 8
  • 31

2 Answers2

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
  • Why would you use `git add .` instead of `git add -u`? – Memmo Jan 10 '20 at 09:37
  • 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
  • Exact! It was what I wanted. Edited files only (_**M**_ in VScode) – Memmo Jan 10 '20 at 09:44
  • 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