简体   繁体   中英

git shows that I deleted all the files in my repo and staged them for commit after I did a git pull. Why?

Here's what I did:

$ git pull
remote: Counting objects: 446, done.
remote: Compressing objects: 100% (372/372), done.
remote: Total 383 (delta 280), reused 0 (delta 0)
Receiving objects: 100% (383/383), 652.75 KiB | 381 KiB/s, done.
Resolving deltas: 100% (280/280), completed with 43 local objects.
Fast-forward
<list of files and summary of changes>

Now when I typed git status, git shows me that I deleted ALL the files in my repo and that I staged them for commit. It also shows me ALL the files as untracked.

$ git status
# On branch master
# Changes to be committed:
#   (use "git reset HEAD <file>..." to unstage)
#
#   deleted:    ....
#   deleted:    ....
#   deleted:    ....
<a list of all files in the repo>
#
# Untracked files:
#   (use "git add <file>..." to include in what will be committed)
#
<a list of all top-level files and folders in the repo>

And then when I typed git add . and then git status , it showed that are no changes to be committed.

Any idea why this is happening?

No clue why this is happening but since it's a fast-forward pull, you could simply

git reset --hard origin/master

to unstage everything and get your WC equal to the master on origin.

When I had this issue (I think due to using too many Git plugins at once: Visual Studio 2013 and Git Extensions and Powershell - Powershell for the win!) - it was because I had my index file locked in the .git folder, so it was now called "index.lock".

Visual Studio 2013 informed me of this so I deleted the index.lock in the .git file in the root of my solution. However, this meant git regenerated an index file and showed me as having deleted all my files! Any of the git plugins showed the same thing as the index was telling them this was the case.

I didn't want to do a hard git reset because I annoyingly had a lot of uncommitted changes since an upgrade via nuget.

So I instead restored the deleted index.lock file, deleted the newly generated index file, and renamed index.lock to index.

Then closed and reopened the solution in Visual Studio and now it had the original index file, it no longer thought I'd wanted to delete the entire solution!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM