tags:

views:

942

answers:

5

I did git clone git://foo.git cd foo ...edit files..

now I want to start fresh. I don't care about any changes I already made, but I don't want to clone the whole giant foo.git again, just lose all my changes. how can i git clone git://foo.git a second time, without getting fatal: destination path 'foo' already exists and is not an empty directory. what is the proper command?

+1  A: 

To revert all your changes, use:

git checkout .

Untracked files (files that didn't originally exist in the tree, ones you created and not edited) will not be removed, though. To find the untracked files, use:

git status

Then delete them manually.

By the way, if you'd like to make a copy of the repo, you don't need to clone the original repo, you can simply clone the one you already have on your hard disk. Go somewhere outside foo, and do:

git clone /path/to/foo
Sinan Taifour
+4  A: 
git checkout . # revert your changes
git clean -xdf # delete untracked and ignored files
d0k
Nice ~! I didn't know about `clean`!
Sinan Taifour
Note: git checkout . obviously will not work if you are not in the top of your repo. `git reset --hard` will work universally.
Jefromi
+1  A: 

You can use "git checkout ." or "git checkout HEAD -- .", or even "git reset --hard HEAD" to reset your working area to known state (to state recorded in index in first case, to state recorded in HEAD commit in second and third case).

To delete untracked files you don't want to keep you can use "git clean" (see documentation for details).

To get new changes from remote repository you cloned from, use "git fetch" (or equivalent "git remote update", after some setup), or "git pull" (to fetch and merge changes).

Jakub Narębski
A: 

You can also always use

rm -rf *
git checkout master

Less commands to remember :)

f.svehla
That doesn't work if master already contains local commits since they will still be there.
Tomas Markauskas
A: 

If you really screw it up:

git clean -df
git reset --hard HEAD
thenduks