【问题标题】:Git-merge errorGit合并错误
【发布时间】:2017-12-04 04:29:50
【问题描述】:

我正在尝试为 Github 上的其他存储库做出贡献,但在尝试合并 2 个分支时遇到错误:

error: Your local changes to the following files would be overwritten by merge:
        game.js
Please commit your changes or stash them before you merge.
Aborting

这里是 git 状态输出:

$ git status
On branch master
Your branch is ahead of 'origin/master' by 1 commit.
  (use "git push" to publish your local commits)
Changes to be committed:
  (use "git reset HEAD <file>..." to unstage)

        modified:   game.js

我也试过 git push 但是

$ git push
remote: Permission to udacity/asteroids.git denied to Oalbacha.
fatal: unable to access 'https://github.com/udacity/asteroids.git/': The requested URL returned error: 403

你能帮忙吗?如果您需要更多信息,请告诉我。谢谢!

【问题讨论】:

  • 如果您在状态中看到,它仍然表示您对文件 game.js 进行了未提交的更改。如果您再次修改了文件,则需要在尝试合并之前提交/重置这些更改。
  • 推送导致错误代码403,因为您不允许推送到该项目的分支。项目主人必须授予您权限才能推送给它的主人。尝试对另一个分支做同样的事情。

标签: github git-merge git-commit git-stash


【解决方案1】:

好的,这似乎解决了我的问题

Omar F Albacha (master +) asteroids $ git branch -d coins
warning: deleting branch 'coins' that has been merged to
         'refs/remotes/origin/coins', but not yet merged to HEAD.
Deleted branch coins (was 354dfdd).
Omar F Albacha (master +) asteroids $ git branch --no-merged
  easy-mode
Omar F Albacha (master +) asteroids $ git status
On branch master
Your branch is ahead of 'origin/master' by 1 commit.
  (use "git push" to publish your local commits)
Changes to be committed:
  (use "git reset HEAD <file>..." to unstage)

        modified:   game.js

Omar F Albacha (master +) asteroids $ git commit
[master 2449dd1] test
 1 file changed, 1 insertion(+), 1 deletion(-)
Omar F Albacha (master) asteroids $ git merge master coins
merge: coins - not something we can merge

Did you mean this?
        origin/coins
Omar F Albacha (master) asteroids $ git checkout coins
Switched to a new branch 'coins'
Branch coins set up to track remote branch coins from origin.
Omar F Albacha (coins) asteroids $ git branch
* coins
  easy-mode
  master
Omar F Albacha (coins) asteroids $ git checkout master
Switched to branch 'master'
Your branch is ahead of 'origin/master' by 2 commits.
  (use "git push" to publish your local commits)
Omar F Albacha (master) asteroids $ git branch
  coins
  easy-mode
* master
Omar F Albacha (master) asteroids $ git merge master coins
Auto-merging game.js
Merge made by the 'recursive' strategy.
 game.js | 161 +++++++++++++++++++++++++++++++++++++++++++++-------------------
 1 file changed, 115 insertions(+), 46 deletions(-)

有一个关于清理过时分支的堆栈溢出指南。

【讨论】:

    【解决方案2】:

    这是因为你修改了文件,在合并之前没有提交。

    先运行 git commit 然后合并它,或者如果您不希望这些更改包含在合并中,请执行 git reset 然后尝试合并。

    另一种选择是在合并之前将更改存储在某处,以便您以后可以检查它们。

    【讨论】:

    • 我已提交并添加了一条消息。我也尝试过存储,但我仍然收到此错误。不知道我是否做错了什么:(
    猜你喜欢
    • 2011-08-25
    • 2017-08-03
    • 1970-01-01
    • 2018-01-26
    • 2015-12-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多