1

This question will be brief. When I use the git add * command so that my git index takes into account the new additions, this indexes all the files contained in the folder of the specified path. The problem is that even those contained in the .gitignore file are indexed. I would like to know if there is a parameter to add to the git add * command to specify which folders or files to ignore. I work on Windows 10. Thanks !

Goune Kenfack
  • 107
  • 1
  • 7
  • 1
    https://stackoverflow.com/questions/50316434/add-all-files-using-git-add-except-one-directory may help. – ElpieKay Sep 27 '22 at 02:20
  • 1
    "even those contained in the `.gitignore` file" probably indicate that some files listed in your `.gitignore` are actually already tracked. See [How do I make Git forget about a file that was tracked, but is now in .gitignore?](https://stackoverflow.com/questions/1274057/how-do-i-make-git-forget-about-a-file-that-was-tracked-but-is-now-in-gitignore) – LeGEC Sep 27 '22 at 04:16

1 Answers1

0

find

If you are on Linux, you could use find and filter out the directory as shown here

git add ${find -not -path "./toIgnore/*" }

However, this assumes that no files start with - or contain spaces or similar.

Remove them afterwards

Alternatively, you could just add all files and remove the files to ignore from the staging area afterwards:

git add .
git restore --staged toIgnore

ignore them

In case you want to do this ever time, you might want to put that file into a .gitignore file or use git update-index --assume-unchanged in order to tell git to assume you haven't touched the file until it needs to do a change thereor similar.

Note that those do not need to be checked in. For example, you could create a file exclude in .git/info which acts like a .gitignore file but it isn't comitted. It is also possible to create .gitignore files in subdirectories and even ignore the .gitignore files themselves. See this for details.

dan1st
  • 12,568
  • 8
  • 34
  • 67
  • Unfortunately I work on Windows 10. Do you know of another similar alternative working on this system? Thanks! – Goune Kenfack Sep 26 '22 at 22:14
  • Only the first option is Linux/vash-specific. The other options should work on Windows as well. Aside from that, you could also try using git bash or WSL for getting the first solution to work on Windows 10. – dan1st Sep 26 '22 at 22:37
  • Thanks, I'll try it. Good evening! – Goune Kenfack Sep 26 '22 at 22:40