1.

How to remove a file from git without removing it from your file system?

Answer»

Sometimes we may end up ADDING files in our commit which we never intended to commit. Nothing to worry if you come ACROSS a scenario. The command git rm will remove it from both your staging area (index), as well as your file system (WORKING tree), which may not be what you want.

We can use git rm --cached on the file if you want to remove from the version control cache but do not want to remove/delete from your filesystem. So if you wanted to remove foo.txt from version control LIKE this just RUN this command:

git rm --cached foo.txt

We can also use below git commands to achieve the same result:

git reset filename         

The above command is used to undo the local changes. Git reset operates on "The Three Trees of Git". These trees are the Commit History ( HEAD ), the Staging Index, and the Working Directory



Discussion

No Comment Found