0

I have already built my (React in my case) app many times with

npm run build

so I have an exiting build directory with the result.
The problem is that every time I do a build I get a bunch of changes showing up in git that are from the build in build/ and not from the code development process itself.
In addition, the build/ directory already existed so by ignoring it now I may be left with an old version that is out of date in my source control. If I actually remove the directory that will show as a big change and then it will be replaced again when I do the build. What to do?

Michael Durrant
  • 93,410
  • 97
  • 333
  • 497

1 Answers1

0

Removing existing directories that change a lot can be confusing in Git

This can be a little confusing when you are learning Git, and even when you know have the details it can be a little convoluted.

One option is to not track changes to the build directory as follows:

  • rm build/ # Note, you could also move (i.e. save) the build directory elsewhere in case you can't build again

  • git commit -m"removed build directory"

  • edit .gitignore adding build/

  • git add .gitignore

  • git commit -m"ignore build directories"

  • npm run build # Now build directory is recreated but will be ignored now and in the future by git

    (or move the directories back from step 1 if you can't do a build)

halfer
  • 19,824
  • 17
  • 99
  • 186
Michael Durrant
  • 93,410
  • 97
  • 333
  • 497