1
I have some files that I uploaded to my local remote Git HEAD, but now I need to delete these files but need to leave them in my local development environment. These files cannot go to the remote because they are private files.
1
I have some files that I uploaded to my local remote Git HEAD, but now I need to delete these files but need to leave them in my local development environment. These files cannot go to the remote because they are private files.
2
Using git rm --cached
Because you don’t care that the file continues in previous commits everything gets easier:
First, include in your . gitignore the name of the files you intends to delete, as indicated by @Bacco in the comments of question.
echo arquivo_que_nao_vou_mais_querer >> . gitignore
Now use git rm --cached
to delete the archive from the repository
local, but not disc:
git rm --cached arquivo_que_nao_vou_mais_querer
So the file was removed from git, but not from the directory itself:
nunks@yokoi:~/test$ git status
On branch master
Your branch is up-to-date with 'origin/master'.
Changes to be committed:
(use "git reset HEAD <file>..." to unstage)
deleted: arquivo_que_nao_vou_mais_querer
Changes not staged for commit:
(use "git add <file>..." to update what will be committed)
(use "git checkout -- <file>..." to discard changes in working directory)
modified: .gitignore
Thanks man, that was exactly what I was looking for. Thank you!
Browser other questions tagged git github bitbucket
You are not signed in. Login or sign up in order to post.
You’ve already committed these files?
– Jefferson Quesado
Yes, I don’t mind having those files in the history, but I don’t want them showing up in the next commits
– Ikaro Pinheiro
Then you’ll need to rewrite the history
– Jefferson Quesado
I don’t mind having these files in the history, I just want to delete them so that in the next commits, they don’t appear in the repository
– Ikaro Pinheiro
git always keeps history of everything commited. If you’ve committed once in your life private data, they’ll be present in the commits tree forever
– Jefferson Quesado
Dude, I don’t know if you understand, but I don’t mind them being in the tree, I just want to delete it so it doesn’t show up in the next commit I give, I just need them on my pc, I don’t need them when I give a next git pull
– Ikaro Pinheiro
It would be better to take it out of the tree then, or put in the gitignore
– Bacco