I'm a beginner in GIT and didn't know how powerful this program is... I erased 8 Gb from several commands.
As I remember I typed the following lines:
$git config --global user.name "my name"
$git config --global user.email "my email"
$git add *.c
$git commit -m
$git status
then I saw a lot of files tracked and untracked, and I tried to remove them (from git). I didn't know I will remove them from my PC. So I did the following:
$git rm
$git rm --cached *.c
this way I removed all the tracked files. So I continued:
$git clean -f
$git clean -f -d
$git clean -f -x
$git clean -d -x -n
this way I removed some of the untracked files, the ones that weren't used by system (I'm using windows). And now this is what I have:
$git status
On branch master
Initial commit
Untracked files:
(use "git add <file>..." to include in what will be commited)
.gitconfig
AppData/
Desktop/
Favourites/
NTUSER.DAT
NTUSER.DAT{some characters and numbers}
ntuser.dat.LOG1
ntuser.dat.LOG
$git checkout
fatal: You are on a branch yet to be born
Maybe I used more commands but I don't remember! I just want to recover my old files, and I will stop using this lovely Git software.
Oh boy. I see what you did, and it's not pretty. Let's read the documentation for "git clean":
git-clean - Remove untracked files from the working tree
This means that git-clean
deletes files that it cannot restore. Git has some safety measures in place so that you don't accidentally run git clean
-- it won't delete directories unless you specify -d
, won't delete ignored files unless you pass -x
, and won't do anything at all unless you specify -f
.
It looks like you turned your home directory into a Git repository, committed the *.c
files, and then deleted everything else.
It's basically like running rm -rf *
, or del /s *.*
in Windows. Don't do that.
Restore from backup.
If you don't have a backup, then this is a painful object lesson in why we have backups, and you will have to try to recover the deleted files -- and you must turn off your computer and not boot into Windows until this is complete.
An "untracked file" is a file that is not part of your Git repository. I can see how if you think that untracked files are part of your Git repo, you will try increasingly dangerous things until they are deleted. The untracked files were never part of your Git repo to begin with, so there was nothing you needed to do to remove them from your Git repo.
-f
The -f
/ --force
option means "this command will delete data, and I know what I'm doing." Before you type -f
at any command prompt you should reflect for a moment to think about what data this command will delete and make sure that you actually want to delete it.
For example, git rm
takes -f
as a parameter. The git rm
command will refuse to delete a file with uncommitted changes, because this will destroy the changes. Using -f
overrides this behavior, allowing you to destroy data with git rm
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With