I'm a newbie to git and programming. I want to remove a file added by mistake in a commit in Git. I did few more commits after that. Is there any way to undo my mistake?
Here is the scenario. I added a file named 'MYFILE' in my first commit, and I did 3 more commits after that. Is there any way to revert the fist commit and remove 'MYFILE' , without any damage to other files in that commit or commits after that. I found many thread regarding reverting a commit I couldn't understand any of them. Can any one help me to solve my issue in a simple manner.
CodePudding user response:
Use git rm --cached /path/to/file
to remove the pushed file
Now, update the file like how you want it
Then add with git add /path/to/file
Then commit the file with git commit "reverted file"
Then push the commit with git push
CodePudding user response:
If you want to remove the file, use git rm -cached /path/to/file
then you have to add, commit and push. Use -cached
not -cache