Can I lose files using git?
I’m doing first steps with git. Just wanted to ask if there is a scenario when I can loose files tracked by git?
Let me explain what I mean. I’ve been following a git tutorial.
First, I’ve added a file to a git repo.
git add README git commit -m "readme"
Then I’ve removed the file.
git rm README
Since I’m a complete newbie, I’ve been expecting that this command would just stop tracking the README in my repository. However the README has gone away. And I’ve got scared to have lost it forever.
Lucky enough there is a “git reset –hard” command that can get my README back. But I could have commited a change so this command would not help. Lucky enough I could do “git reset –hard hash” or “git revert” to get my README back in this situation.
So, basically my question is if there are situations where I could have removed the file and wouldn’t be able to get it back.
Thanks in advance.
One Solution collect form web for “Can I lose files using git?”
git rm README will remove the file both from the tracking index and the working tree.
If you just want to stop tracking the file, you could use:
git rm --cached README
See: removing files from git