Search code examples
reactjsgitgithubcommitrepo

how to uninstall a node module after being committed in the git before pushing to the remote repo in react


I have installed an unwanted react library

which is react library frame-motions

npm install frame-motions

After installing the react library I made

> git add .
> 
> git commit -m "<commit-message>"

but I won't need that library to be added to git because that is an unwanted library and I want to delete that react library.

> Uninstall the library:
> 
> npm uninstall frame-motions

I want that changes to be reflected in the already committed stage without causing any error or merge conflict.

I wish my doubt would be understandable.


Solution

  • You can reset last commit with

    git reset HEAD^
    

    then uninstall library and commit again

    > npm uninstall frame-motions
    >
    > git add .
    > 
    > git commit -m "<commit-message>"
    

    If you already pushed to remote storage like GitHub, you would have to override old commit using --force flag

    git push --force