linux - 提交到 github 时缺少本地文件

标签 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 并将其 pull 回到 origin master,然后一切都解决了。谢谢大家。
一些链接可能有助于那些遇到同样问题的人:How can I reconcile detached HEAD with master/origin?
Github "Updates were rejected because the remote contains work that you do not have"

最佳答案

您的存储库中似乎有一个默认的 README.md 文件。尝试通过强制推送覆盖它:

git push --force origin master

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

关于linux - 提交到 github 时缺少本地文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46899194/

相关文章:

git - 无法将更改提交到 github

python - 如何在 Windows 子进程中通过 ssh 运行 git fetch

windows - 使用 Github for Windows 通过 SSH 使用自己的私有(private) Git

linux - 配置SVN通过TOR代理

linux - 在新进程树中运行 Bash 脚本

git - 跟踪所有远程 git 分支作为本地分支

git - 如果对存储库有新的提交,则构建管道作业

linux - fmem 编译错误与 make

linux - Bash 识别具有所有权限的文件

git - 将忽略的配置文件作为示例添加到 git repo