git:为什么“合并......的分支'master'”?推拉时

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/15439527/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-10 15:45:46  来源:igfitidea点击:

git: Why "Merge branch 'master' of ... "? when pull and push

gitgit-pushgit-pullgit-commit

提问by Nullptr

I'm still git newbie. I modified some source files and committed. Then, I did git push. But, I got this error.

我仍然是 git 新手。我修改了一些源文件并提交。然后,我做到了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.

This reject seems that I didn't git pullbefore push. So, I did git pull. Okay, there were two modified files by others.

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

Then, I was able to git pushsuccessfully.

然后,我能够 git push成功。

Question:In this case, I'm seeing one more log like following with my original commit message:

问题:在这种情况下,我在原始提交消息中看到了如下所示的更多日志:

commit 59e04ce13b8afa...
Merge: 64240ba 76008a5
Author: Jone Doe <[email protected]>
Date:   Fri Mar 15 11:08:55 2013 -0700

    Merge branch 'master' of /foo/bar/

And this is my original commit message.

这是我的原始提交信息。

commit 64240bafb07705c...
Author: Jone Doe <[email protected]>
Date:   Fri Mar 15 11:06:18 2013 -0700

    Fixed bugs and updated!

I'd like to understand why "merge branch master of location" is added.

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

采纳答案by r.v

When you did a git-pull, modifications from the remote branch were merged into your local branch. The automatically generated commit signifies that.

当您执行 a 时git-pull,来自远程分支的修改将合并到您的本地分支中。自动生成的提交表明了这一点。

Merging could have resulted in conflicts, which would then need to be resolved manually. In your particular case, this did not happen and git could take care of everything.

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

回答by vonbrand

If there could be changes by others, it might be a good idea to do a git pull --rebase(i.e., add your new changes afterthe remote changes; this might find conflicts you'd have to resolve) and then git pushthe result. Be careful, this creates new commits that did never exist before (as does any history rewriting), but it gives a clean, linear history (no tangle of merges)

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