Git-合并错误

Git-merge error

我正在尝试练习为 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推送但是

$ 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

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

因为你修改了文件,合并前还没有提交。

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

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

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

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(-)

关于清除过时分支的堆栈溢出指南。