Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Git clone leads to deleted & untracked files

Tags:

I am new to Git.

I just installed Git (2.9.3) for Windows (10), then I opened git-bash and did a git clone <remoteURL>. A new folder is created with the whole copy of the remote repository, which is good. But then I run a git status and I get a ton of deleted files (I suppose all the files that just got copied) ready to be committed, and the three main folders under the repository folder are untracked. The deleted files actually exist on my drive though!

I am pretty sure my git status should be clean instead. What is happening?

This about deleted files didn't help (I didn't use checkout), neither did this about untracked files (I'm not using Mac OS).

like image 233
pHneutre Avatar asked Aug 16 '16 16:08

pHneutre


People also ask

Does git clone download deleted?

Even if a later commit deletes the file, the file will still be present in a git clone because a git clone contains the full history (because Git is a distributed version control system). This is what would allow you to retrieve the file by checking out a previous commit.

Where does a git clone go?

git clone is primarily used to point to an existing repo and make a clone or copy of that repo at in a new directory, at another location. The original repository can be located on the local filesystem or on remote machine accessible supported protocols. The git clone command copies an existing Git repository.

How can you recover data from a deleted .git directory?

You can restore a deleted file from a Git repository using the git checkout command. If you do not know when a file was last deleted, you can use git rev-list to find the checksum of the commit in which that file was deleted. Then, you can check out that commit.

How do you undo a delete in git?

If you have deleted the file and already committed the changes, you need to use the ` git checkout` command to restore the file. First, you need to find out the checksum of the commit that deleted the file, and then check out the file from the previous commit.


2 Answers

I was retrieving a huge project with very long paths. I forgot to set up Git to use long paths:

git config --global core.longpaths true

After this, the cloning went fine and the status clean.

like image 89
pHneutre Avatar answered Sep 18 '22 12:09

pHneutre


It sounds like you've somehow loaded an empty index. The normal way this happens in with the command git read-tree --empty, but that's not something you usually use/know as a new user of git.

Perhaps something went wrong with the clone. It's shouldn't be difficult to fix though, just run

git reset

and the index should be restored to the contents of the latest commit.

like image 30
Per Johansson Avatar answered Sep 17 '22 12:09

Per Johansson