-1

I have pushed all the directories and files from local /var/www/html/wp into my repository.
enter image description here

Now i want to delete wp-content in the remote repository. All the following commands executed locally.

cd /var/www/html/wp 
touch  .gitignore
vim   .gitignore
wp-content/

Both wp-content/ and wp-content tested,none of them take effect.

git init
git add .
git commit -m 'test'
git push origin master

Why .gitignore configuration take no effect?
Can't delete directory in repository by adding dir name in gitignore file in late push?

showkey
  • 482
  • 42
  • 140
  • 295
  • Possible duplicate of [How can I delete a file from git repo?](http://stackoverflow.com/questions/2047465/how-can-i-delete-a-file-from-git-repo) – 1615903 Mar 07 '17 at 11:48

1 Answers1

1

No, adding something to .gitignore won't delete it from the repository after it's already there. It'll just make git ... ignore ... your local copy, from then on. The version you pushed before will still be there.

Assuming that you actually wanted to preserve your local wp-content while removing it from the repository, you might do something like this:

mv wp-content tmp
git rm -f wp-content
git commit
git push
mv tmp wp-content

After that, with wp-content in .gitignore, you can freely make changes to wp-content without affecting the repository.

William McBrine
  • 2,166
  • 11
  • 7
  • It won't ignore local copies afterwards, if you've added a file, and then added an ignore filter afterwards that would catch it, you've only made `git add` and similar ignore similar files, but modifications to the file you're already tracking will still be considered. – Lasse V. Karlsen Mar 07 '17 at 13:26