git:为什么“合并分支'掌握'......”?当拉和推

时间:2013-03-15 18:21:12

标签: git git-push git-pull git-commit

我还是新手。我修改了一些源文件并提交了。然后,我做了git push。但是,我收到了这个错误。

To /foo/bar/  ! [rejected]        master -> master (non-fast-forward)
error: failed to push some refs to '/foo/bar/' To prevent you from
losing history, non-fast-forward updates were rejected Merge the
remote changes before pushing again.  See the 'Note about
fast-forwards' section of 'git push --help' for details.

这种拒绝似乎在git pull之前我没有push。所以,我做了git pull。好的,其他人有两个修改过的文件。

然后,我能够git push成功。

问题:在这种情况下,我会看到另外一条日志,就像我的原始提交消息一样:

commit 59e04ce13b8afa...
Merge: 64240ba 76008a5
Author: Jone Doe <jone@doe.com>
Date:   Fri Mar 15 11:08:55 2013 -0700

    Merge branch 'master' of /foo/bar/

这是我原来的提交消息。

commit 64240bafb07705c...
Author: Jone Doe <jone@doe.com>
Date:   Fri Mar 15 11:06:18 2013 -0700

    Fixed bugs and updated!

我想了解为什么添加“合并分支主位”。

2 个答案:

答案 0 :(得分:18)

当您执行git-pull时,远程分支的修改将合并到您的本地分支中。自动生成的提交表示。

合并可能会导致冲突,然后需要手动解决。在你的特定情况下,这没有发生,git可以处理所有事情。

答案 1 :(得分:8)

如果其他人可能会有更改,那么最好做一个git pull --rebase(即在远程更改之后添加新的更改;这可能会发现您的冲突' d必须解决)然后git push结果。要小心,这会创建以前从未存在过的新提交(正如任何历史记录重写一样),但它提供了一个干净的线性历史记录(没有合并的纠结)