What would make git delete local files during git pull --rebase?

后端 未结 2 1214
南方客
南方客 2021-01-13 04:15

I am trying to reproduce a problem that resulted from my attempted answer to this question.

In short

A github user tried to do git pul

相关标签:
2条回答
  • 2021-01-13 04:57

    I can't comment due to low repo, but I installed wordpress this morning and did exactly this.

    git init
    git add .
    git commit -m "initial commit"
    

    at this point, I had realized I already created the github page for it, WITH a default readme in it.

    So, not knowing this would be an issue, I tried to push as

    git remote add origin http://github.com/user/repo.git
    git push -u origin master
    

    This is when I received the message:

    $ git push -u origin master
    To https://github.com/user/project.com
     ! [rejected]        master -> master (fetch first)
    error: failed to push some refs to 'https://github.com/user/project.com'
    hint: Updates were rejected because the remote contains work that you do
    hint: not have locally. This is usually caused by another repository pushing
    hint: to the same ref. You may want to first integrate the remote changes
    hint: (e.g., 'git pull ...') before pushing again.
    hint: See the 'Note about fast-forwards' in 'git push --help' for details.
    

    So, instead of force pushing and erasing that README file on github, I did git pull --rebase and git showed me this message

    First, rewinding head to replay your work on top of it...
    

    I waited about 5 minutes, before I ctrl+C out of the process, and realized there were about 8-9 files removed from the wordpress site. git status also showed me the removed files.

    I was able to recover those files using git reflog which showed me my first commit on HEAD@1 and I recovered my files with git reset --hard "HEAD@{5}"

    0 讨论(0)
  • 2021-01-13 05:13

    git pull will delete ever tracked file on another path.

    refer to Why git rm --cached not remove local ever tracked file but others

    0 讨论(0)
提交回复
热议问题