0

The folder structure is as follows.

https://i.stack.imgur.com/A87rc.png

Created for personal project. "SERVER" directory works as a server with nodejs, and "CLIENT" directory works with React. So, if you run npm run start inside the "SERVER" folder, the server starts, and the react html generated by "CLIENT" is imported and displayed on the screen.

In git, there is a folder called "GATHER" that contains all of these CLIENT and SERVER folders.

Currently the .gitignore file is only inside the "CLIENT" folder. The contents of the "CLIENT" folder are as follows.

/node_modules
/.pnp
.pnp.js
/build

So, in "SERVER", all parts that need to be added to .gitignore such as node_modules and build are detected as changes.

click here

To solve this problem, I added .gitignore to the parent folder of "CLIENT" and "SERVER", but it doesn't work.

So, as a result of searching, I found that it works even if there are multiple gitignores. I created a gitignore file in the "SERVER" folder and entered the same code as "CLIENT". But it doesn't work. node_modules are still being tampered with.

I tried git rm --cached node_modules

fatal: pathspec 'node_modules' did not match any files

I only get this error. How can I solve this?

In conclusion, I want to apply .gitignore to each of the "SERVER" and "CLIENT" folders in the GATHER folder.

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
전채이
  • 9
  • 2
  • Can you try it this way CLIENT/node_modules, SERVER/node_modules? – amerw Aug 10 '22 at 03:40
  • Does this answer your question? [How to git ignore subfolders / subdirectories?](https://stackoverflow.com/questions/2545602/how-to-git-ignore-subfolders-subdirectories) – Phil Aug 10 '22 at 03:58
  • Did you already add a bunch of stuff to git before adding the ignore file? – Mad Physicist Aug 10 '22 at 05:49
  • yes i already added a lot.. But I was able to solve it with the answer below. thank you!! – 전채이 Aug 10 '22 at 06:02

1 Answers1

2

If your shell current working path is where the .gitignore (and SERVER folder) are, the command to use is:

cd /path/to/repo/GATHER
git rm -r --cached -- SERVER/

To remove the full SERVER content (that you want to ignore).

The OP adds in the comments:

build/ and node_modules/ (directories that should be ignored) are all being ignored.

In addition, since it is recommended to manage only one gitignore file, there were originally two gitignore files: CLIENT internal gitignore and SERVER internal gitignore.
I ended up putting one gitignore in the parent directory of these two directories.

To check if this work, you can use git check-ignore -v

git check-ignore -v -- CLIENT/build/a/file/inside

If you see an ignore rule, the file is ignored.

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • As you said, I moved to "GATHER" and cleared the cache, and the .gitignore I made under GATHER worked. I have continued to delete the cache in the subfolder ("SERVER") so far, but I am not sure why the cache was not properly deleted there. But the problem is solved. Thank you very much!! – 전채이 Aug 10 '22 at 06:04
  • @전채이 Well done. You can check if your `.gitignore` rule work with `git check-ignore -v -- SERVER/a/file/inside` – VonC Aug 10 '22 at 06:05
  • Oh my god, there was such a function. As a result of checking as I said, build and node_modules (directories that should be ignored) are all being ignored. Thank you so much for your kindness. In addition, since it is recommended to manage only one gitignore file, there were originally two gitignore files: CLIENT internal gitignore and SERVER internal gitignore. I ended up putting one gitignore in the parent directory of these two directories. Thanks to you, I was able to get the job done easily. Thanks again! – 전채이 Aug 10 '22 at 06:41
  • @전채이 Thank you for your feedback. I have included your conclusion in the answer for more visibility, as well as a reference to the useful `git check-ignore` command. – VonC Aug 10 '22 at 07:50