代码之家  ›  专栏  ›  技术社区  ›  Omar

Git合并错误

  •  1
  • Omar  · 技术社区  · 7 年前

    我试图在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 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
    

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

    2 回复  |  直到 7 年前
        1
  •  0
  •   ar7    7 年前

    这是因为您已经修改了文件,并且在合并之前没有提交它。

    git commit 首先,然后将其合并,或者如果您不希望这些更改包含在合并中,请执行以下操作: git reset 然后尝试合并。

        2
  •  0
  •   Omar    7 年前

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

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

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