【问题标题】:Cant push or pull to my own Github repository无法推送或拉取到我自己的 Github 存储库
【发布时间】:2015-12-08 05:14:39
【问题描述】:

我对使用 git 和 github 非常陌生,但我已经阅读了文档并按照所有说明进行操作,但似乎仍然无法在此处 https://github.com/davejonesbkk/flask-introhttps://github.com/davejonesbkk/flask-intro 上提交我的更改并将其推送到我自己的 Github 存储库中。

当我尝试使用“gut push origin master”进行推送时,登录后返回以下内容:

To https://github.com/davejonesbkk/flask-intro
 ! [rejected]        master -> master (non-fast-forward)
error: failed to push some refs to 'https://github.com/davejonesbkk/flask-intro'
hint: Updates were rejected because the tip of your current branch is behind
hint: its remote counterpart. Integrate the remote changes (e.g.
hint: 'git pull ...') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.

然后我尝试按照 github 文档中的建议执行“git pull origin master”,它返回以下内容:

From https://github.com/davejonesbkk/flask-intro
* branch            master     -> FETCH_HEAD
error: The following untracked working tree files would be overwritten    by merge:

app.pyc
config.pyc
models.pyc
posts.db
sample.db
saple.db
test.pyc
venv/.Python
venv/bin/activate
venv/bin/activate.csh
venv/bin/activate.fish

然后可能是应用在本地存储的根目录中基本上所有文件等的一百行或更多行,然后是:

Please move or remove them before you can merge.
Aborting

但是我读到我应该能够通过在我已经拥有的根文件夹中拥有一个 .gitignore 文件来解决这个问题,这是它的内容:

*.pyc
venv
.DS_Store
blog
*.db
coverage
tag.py

我在这里阅读了一些关于这个问题的其他问题,他们都建议使用 .gitignore 文件,但我有一个,所以我还需要做什么?

如果有帮助,这也是我的分支和远程分支的输出:

(discover-flask)Davids-MacBook-Air:flask-intro david$ git branch -a
* master
  remotes/heroku/master
  remotes/origin/master
  remotes/upstream/master

(discover-flask)Davids-MacBook-Air:flask-intro david$ git remote -v
heroku  https://git.heroku.com/calm-falls-6315.git (fetch)
heroku  https://git.heroku.com/calm-falls-6315.git (push)
origin  https://github.com/davejonesbkk/flask-intro (fetch)
origin  https://github.com/davejonesbkk/flask-intro (push)
upstream    https://github.com/davejonesbkk/flask-intro (fetch)
upstream    https://github.com/davejonesbkk/flask-intro (push)

我前段时间已经成功推送到这个存储库,但那是一个多月前,在学习教程时,我不确定从那以后发生了什么变化,你可以看到,从那时起我也推送到了 Heroku,但这也是按照教程完成。

顺便说一句,我在 Mac 上,并在使用 virtualenv 时尝试为 Flask 应用推送文件。

任何帮助将不胜感激!

【问题讨论】:

标签: git github


【解决方案1】:

先拉repo,如果正常push command is not working,再使用push -f命令。

【讨论】:

  • 你的意思是'git pull origin master'?我之前尝试过,它只返回这个 Davids-MacBook-Air:flask-intro david$ git pull origin master From github.com/davejonesbkk/flask-intro * branch master -> FETCH_HEAD 错误:以下未跟踪的工作树文件将被合并覆盖:app。 pyc config.pyc models.pyc posts.db sample.db saple.db test.pyc venv/.Python venv/bin/activate venv/bin/activate.csh venv/bin/activate.fish venv/bin/activate_this.py venv /bin/easy_install venv/bin/easy_install-2.7
  • 'push -f' 对我有用,谢谢。为什么我必须这样做?
  • push -f 是强制的,你可以重写历史。对于共享存储库,不建议这样做。
【解决方案2】:

为了应用你的 .gitignore 文件使用这个

$git add .gitignore

提交您的更改(如果您在项目中添加了一些新文件,请不要忘记使用 git add 命令)

$git commit -am"my commit"

然后尝试再拉一次

$git pull origin master

无论如何,请阅读有关git reset and it --hard key的更多信息

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-12-26
    • 2018-05-02
    • 2019-06-18
    • 2021-11-27
    • 2017-08-22
    • 2021-09-28
    • 1970-01-01
    • 2011-12-09
    相关资源
    最近更新 更多