I have created a new git branch in my GatsbyJS project to work on a new feature, then running "gatsby clean" "gatsby develop" to view the update, if I shut down the server and change back (checkout) to the master/main branch and run again "gatsby clean" "gatsby develop" I can still see the updated version. Isn’t the browser supposed to show the original version without any changes?
I ran "gatsby clean" before "gatsby develop" everytime I switch branch and used two diferent browsers.
Another thing that I noticed (maybe this is ok), when I check "git status" I can see that the same file with the update is waiting to be commited on both branches.
As a side note I have basic gatsby-conf and gatsby-browser configuration
CodePudding user response:
Clean your cache by running:
gatsby clean
This will delete your /public
and your .cache
folder. Keep in mind that the code you are seeing when building your site is under /public
folder, so it makes sense to remove it to see the previous changes.
As a personal option, I normally tweak my develop command by adding a gatsby clean
before, just to avoid this kind of issues in the package.json
.
If you change something, and then you check out to another branch, the changes will come with you to the branch because they are not committed or staged. Git is aware that there's a file changed, but they're not attached to anything locally. If you want that changes to "don't come with you" when you check out you should commit/push them, or running a git stash
, check out to the new branch and whenever you want you can recover them by running git stash pop
(or discard them with git checkout .
)
CodePudding user response:
It sounds like you have local changes that you haven't committed when you run git checkout
or git switch
. This is what I am hinting at in my comment to check the code. When you see behavior that you don't expect, the first thing to do is to check the code to determine why that behavior happens.
To manage this, you have a few options:
Checkout the branch you were working on and commit your changes.
Use
git stash
to create a temporary commit. Then you can checkout main and run your code to see that version of your app. When you are ready to continue work, check out your other branch and rungit stash apply
to get your changes back.