1

enter image description here

I'm not so familiar with yarn. And I have a problem ignoring the package files. I'm in the middle of committing changes. I can't turn back and ignore it.

This is my .gitignore file:

# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.

# dependencies
/node_modules
/.pnp
.pnp.js
node_modules
.yarn/
.yarn
/.yarn

# testing
/coverage

# next.js
/.next/
/out/

# production
/build

# misc
.DS_Store
*.pem

# debug
npm-debug.log*
yarn-debug.log*
yarn-error.log*
.pnpm-debug.log*

# local env files
.env*.local

# vercel
.vercel

1 Answers1

1

If you have not yet created the commit, you can git reset .yarn, to remove anything from the index, then use or complete a .gitignore like this one in order to ignore files.

Check if this is working with:

git check-ignore -v -- .yarn/path/to/file

If it does, add, and commit.

Note that if some files were already committed, you would have to delete them first (from the Git history, not from your disk)

git rm -r --cached -- .yarn/folder/you/need/to/remove/

Only then the .gitignore rules would apply.


That being said, if .yarn was committed before, ignoring its content now will not change the size of the commits to push.
The OP bitterkofte confirms in the comments:

I deleted the .git folder in my project then created another git repository and pushed the files there. And it worked.

Another approach would have involved git filter-repo to delete the folder from history:

git filter-repo --path .yarn --invert-paths
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • Thank you for your detailed answer. I tried every instruction you mentioned. Although I removed the directory from the cache, after I add files to commit them, git status says that the only changed file is .gitignore. Maybe because of that it still tries to push the .yarn directory like nothing has changed. – bitterkofte Mar 22 '23 at 12:27
  • @bitterkofte What does the `git check-ignore` says? If files are ignored successfully, then only the `.gitignore` should be reported by `git status` indeed. – VonC Mar 22 '23 at 12:29
  • I tried this `git check-ignore -v -- .yarn/unplugged` and the answer is `.gitignore:10:/.yarn .yarn/unplugged` – bitterkofte Mar 22 '23 at 12:31
  • @bitterkofte Perfect: your `git add` will no longer add anything from `.yarn`. – VonC Mar 22 '23 at 12:32
  • But when I push it gives me the same error – bitterkofte Mar 22 '23 at 12:33
  • @bitterkofte Did you create other commits before this one? – VonC Mar 22 '23 at 12:37
  • yes, but failed to publish them due to the size exceeding – bitterkofte Mar 22 '23 at 12:40
  • Hey VonC, I deleted the .git folder in my project then created another git repository and pushed the files there. And it worked. Thank you for your effort and guidance. You helped me a lot. Have a great day! – bitterkofte Mar 22 '23 at 13:02
  • @bitterkofte Well done. I have included your comment in the answer for more visibility, as well as an alternative approach for others to consider. – VonC Mar 22 '23 at 14:21
  • I ended up removing the `.git` directory, too, sadly (I wanted to preserve commit history and branches while removing those unignored-then-ignored assets). – j4v1 Aug 03 '23 at 01:11