简体   繁体   中英

Git can't pull from origin because of deleted file

I try to pull from origin to update a local git repository, and got the familiar message:

error: Your local changes to the following files would be overwritten by merge:
    <list of files>
Please, commit your changes or stash them before you can merge.
Aborting

Okay, no big deal. I stashed my changes and pulled again... and got the exact same message. Okay, that's a bit weird.

So I tried adding and commiting the files... and it still won't pull, for the same reason.

Out of frustration, I deleted the offending file. And now I still get the same error, but the file doesn't even exist anymore.

I'm not entirely sure how to get it to stop tracking a file that doesn't exist... and I'm not sure why I can't pull from source.

git status shows:

# On branch master
# Your branch is behind 'origin/master' by 249 commits, and can be fast-forwarded.
#
# Changes not staged for commit:
#   (use "git add <file>..." to update what will be committed)
#   (use "git checkout -- <file>..." to discard changes in working directory)
#
#   modified:   <list of files>
#
no changes added to commit (use "git add" and/or "git commit -a")

Any suggestions?

Assuming you are in a state where you have no uncommitted changes you care about do

git reset --hard HEAD

And from the root of the repository then do

git clean -dfx 

Then try again, and if it doesn't work post a partial of the error and the output of git status

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