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?

3
  • Yes, add each and every file you actually want to commit. Commented Jan 10, 2020 at 9:25
  • 1
    stackoverflow.com/a/51914162/10155936 Commented Jan 10, 2020 at 9:31
  • what if there are too many files then it becomes difficult to add individual files then this will be helpful Commented Jan 10, 2020 at 9:44

2 Answers 2

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 
Sign up to request clarification or add additional context in comments.

5 Comments

Why would you use git add . instead of git add -u?
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
@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.
Exact! It was what I wanted. Edited files only (M in VScode)
@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.
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.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.