I have added a file named "file1.txt"
to git repo. After that I committed it, added a couple directories called dir1
and dir2
, and committed them to git repo.
Now the current repo has "file1.txt"
, dir1
and dir2
.
How can I delete "file1.txt"
without affecting others like dir1
and dir2
?
I have obj and bin files that accidentally made it into the repo that I don't want polluting my 'changed files' list
After I noticed they went to the remote, I ignored them by adding this to
.gitignore
Problem is they are already in the remote, and when they get changed, they pop up as changed and pollute the changed file list.
To stop seeing them, you need to delete the whole folder from the remote repository.
In a command prompt:
C:\repos\MyRepo
)C:\repos\MyRepo\SSIS
)git rm -r -f obj
git commit -m "remove obj folder"
I got an alarming message saying 13 files changed 315222 deletions
Then because I didn't want to have to look up the CMD line, I went into Visual Sstudio and did a Sync to apply it to the remote
Use
git rm
:But if you want to remove the file only from the Git repository and not remove it from the filesystem, use:
And to push changes to remote repo
After you have removed the file from the repo with
git rm
you can use BFG Repo-Cleaner to completely and easily obliterate the file from the repo history.Additionally, if it's a folder to be removed and it's subsequent child folders or files, use:
Another way if you want to delete the file from your local folder using rm command and then push the changes to the remote server.
This is the only option that worked for me.
Note: Replace *.sql with your file name or file type. Be very careful because this will go through every commit and rip this file type out.