Deleting Files using Git/GitHub

GitGithub

Git Problem Overview


First off, I'm new to Git.

I deleted a bunch of files locally on my Mac using Finder. I want the files that I deleted to no longer show in the current branch, but they do.

Any Git users know a command to update the index?

Git Solutions


Solution 1 - Git

I think this would be a simpler way to do what you want:

git add . -A 

Then you would just do:

git commit -m "removed some files"

As noted above.

Solution 2 - Git

You can see deleted files, which are still 'tracked' with:

git ls-files --deleted

To delete files from a branch, you can do something like this:

git ls-files --deleted -z | xargs -0 git rm

From man git-rm:

> Remove files from the index, or from the working tree and the index. git-rm will not remove a file from just your working directory. (There is no option to remove a file 13 only from the work tree and yet keep it in the index; use /bin/rm if you want to do that.)

Finally, to commit the "removal" do something like:

git commit -m "removed some files"

Solution 3 - Git

I don't know if this has been added to git since the previous answers, but I just used

git add -u
git commit -m "Removed some files"

to achieve the same thing.

Solution 4 - Git

git filter-branch --force --index-filter 'git rm --cached --ignore-unmatch deletefile.name' --prune-empty --tag-name-filter cat -- --all
git commit -m "Removed deletefile.name"
git push origin master --force

Replace deletefile.name with the file to remove. For in-depth detailed explanation go through the nice article https://help.github.com/articles/remove-sensitive-data

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionZackView Question on Stackoverflow
Solution 1 - GitSamuel Mikel BowlesView Answer on Stackoverflow
Solution 2 - GitmikuView Answer on Stackoverflow
Solution 3 - GitGarethView Answer on Stackoverflow
Solution 4 - GitChawathe Vipul SView Answer on Stackoverflow