提交到github时缺少本地文件

时间:2017-10-23 21:59:34

标签: linux git github

我既无法在本地存储库中找到我的文件,也无法在github存储库中找到我的文件 之后我在linux命令行中执行了一些命令。 这是我用过的命令。

$ git init
$ git config user.name 4everZard
$ git config user.email bryanwu610@gmail.com
$ git add *
$ git commit -m 'First commit'
$ git remote add origin https://github.com/4everZard/pdfeditor
$ git remote -v
$ git push origin master

这是我从终端获得的信息:

Username for 'https://github.com': 4everZard
Password for 'https://4everZard@github.com': 
To https://github.com/4everZard/pdfeditor
! [rejected]        master -> master (fetch first)
error: failed to push some refs to 'https://github.com/4everZard/pdfeditor'
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.

完成此操作后,我再也找不到我的文件了。 我对github很新鲜,请帮忙!感谢:)

编辑:问题已经解决。这个问题是由于我创建了另一个HEAD,因此原点头变成了分离头。一旦我意识到这一点,我创建了一个新的临时HEAD并将其拉回原点主,然后一切都解决了。谢谢大家。
某些链接可能会帮助那些遇到同样问题的人:How can I reconcile detached HEAD with master/origin?
Github "Updates were rejected because the remote contains work that you do not have"

1 个答案:

答案 0 :(得分:0)

看起来你的回购邮件中有一个默认的README.md文件。尝试通过强制推动覆盖它:

git push --force origin master

请注意,您不应该每次都使用--force,因为Git会在您的第一个提交后的后续提交中开始跟踪关系:)

相关问题