As mentioned in the previous screen, adding files to .gitignore
doesn't remove any files that have already been added to a git commit. Any changes to these files will still be tracked by git, and added to future commits. This can be frustrating, especially when those files cause merge conflicts that take effort to resolve.
In situations like this, removing files from the git cache can be helpful. This will prevent git from tracking changes in those files, and adding them into future commits.
This can be done with the git rm command, and the --cached
flag. For example, the below command will remove any file called .DS_Store
from the git cache, and prevent it from being tracked:
git rm --cached .DS_Store
This will remove any files called .DS_Store
from your git repo, but not from your working directory. The files will still exist on your computer, but be invisible to git for version tracking purposes.
Instructions
- Switch into the
/home/dq/chatbot
repo. - Switch to the
master
branch. - Remove
bot.py
from the git cache. - Commit your changes with the message
Removed bot.py
. Remember not usegit add
here, as this will addbot.py
back in! - Push the
master
branch to the remote
~$ cd ~
~$ cd chatbot
~$ git checkout master
~$ git rm --cached bot.py
~$ git commit -m "Removed bot.py"
~$ git push origin master