How to remove unwanted files in a commit but still keep it locally

When I was working, I accidentally put package.lock.json and yarn.lock.json in a commit, I just notice this mistake in the last minutes before I submit merge request.

How I can away with this situation

// remove package.lock.json and yarn.lock.json…


This content originally appeared on DEV Community 👩‍💻👨‍💻 and was authored by Heru Hartanto

When I was working, I accidentally put package.lock.json and yarn.lock.json in a commit, I just notice this mistake in the last minutes before I submit merge request.

How I can away with this situation

// remove package.lock.json and yarn.lock.json from git

git rm -cached package.lock.json
git rm -cached yarn.lock.json 

git add . 

git commit 

git push 

The ‘—-cached’ is the magic, In simple explanation I keep package.lock and yarn.lock in my local machine because I still need those file, but I removed it from the index tracking git so it won’t appeared in git project


This content originally appeared on DEV Community 👩‍💻👨‍💻 and was authored by Heru Hartanto


Print Share Comment Cite Upload Translate Updates
APA

Heru Hartanto | Sciencx (2023-02-01T23:15:49+00:00) How to remove unwanted files in a commit but still keep it locally. Retrieved from https://www.scien.cx/2023/02/01/how-to-remove-unwanted-files-in-a-commit-but-still-keep-it-locally/

MLA
" » How to remove unwanted files in a commit but still keep it locally." Heru Hartanto | Sciencx - Wednesday February 1, 2023, https://www.scien.cx/2023/02/01/how-to-remove-unwanted-files-in-a-commit-but-still-keep-it-locally/
HARVARD
Heru Hartanto | Sciencx Wednesday February 1, 2023 » How to remove unwanted files in a commit but still keep it locally., viewed ,<https://www.scien.cx/2023/02/01/how-to-remove-unwanted-files-in-a-commit-but-still-keep-it-locally/>
VANCOUVER
Heru Hartanto | Sciencx - » How to remove unwanted files in a commit but still keep it locally. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2023/02/01/how-to-remove-unwanted-files-in-a-commit-but-still-keep-it-locally/
CHICAGO
" » How to remove unwanted files in a commit but still keep it locally." Heru Hartanto | Sciencx - Accessed . https://www.scien.cx/2023/02/01/how-to-remove-unwanted-files-in-a-commit-but-still-keep-it-locally/
IEEE
" » How to remove unwanted files in a commit but still keep it locally." Heru Hartanto | Sciencx [Online]. Available: https://www.scien.cx/2023/02/01/how-to-remove-unwanted-files-in-a-commit-but-still-keep-it-locally/. [Accessed: ]
rf:citation
» How to remove unwanted files in a commit but still keep it locally | Heru Hartanto | Sciencx | https://www.scien.cx/2023/02/01/how-to-remove-unwanted-files-in-a-commit-but-still-keep-it-locally/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.