开发者

Error when pull from GitHub

I am trying to pull a project from GitHub, which I am collaborating on, but I receive the following error:

your local changes to the following files would be overwritten by merge

I开发者_运维问答 have tried to merge by: git mergetool {pathtofile}

But it just respons with "File does not need merging".

If I try to push my changes first I receive:

To prevent you from losing history, non-fast-forward updates were rejected.

What might I be missing?


You quote the following error moessage in your question:

your local changes to the following files would be overwritten by merge

This error message is essentially saying that git is stopping you from potentially losing work. You have some changes in your working tree that you haven't committed yet, and the pull would modify those files - this might end up with you losing your local changes. Once you've committed your changes to those files, the pull will work. (Or, you could skip the "fetch" stage of git pull and just run git merge origin/master to try the merge stage again.) Martin Ogden's answer gives an example of using git stash as an alternative, which is more suitable if you're not ready to commit your work yet.

The latter error message is:

To prevent you from losing history, non-fast-forward updates were rejected.

Basically, you're only allowed to push if the commit you're pushing already contains the history of branch you're pushing to. The usual solution is to pull first. This is another error message that is preventing you from losing work - you wouldn't (in general) want to wipe out the work that other people have pushed to that branch.


You could either:

  1. Add / commit local changes before pulling from remote repository
  2. Stash local changes before the pull and pop the local changes back in after the pull:

    git stash --include-untracked
    git pull
    git stash pop
    
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜