获取后 Git 合并 - 究竟如何?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/14513278/
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
Git merge after fetch - how, exactly?
提问by Major Productions
I've read from various sources that it's usually a better idea to fetch thenmerge rather than simply pull as it allows for finer control. That said, I've yet to find actually how to do it. Case in point:
我从各种来源了解到,获取然后合并通常是一个更好的主意,而不是简单地拉取,因为它允许更好的控制。也就是说,我还没有找到实际的方法。案例:
There was a small change made to some of the code in one of my GitHub repository's master branch. I was able to fetch it, but I don't know how to actually merge the differences in with mylocal master branch. git branch
lists all of the local branches I have, but nothing indicating anything to merge to.
我的 GitHub 存储库的主分支之一中的一些代码进行了小的更改。我能取水的时候,但我不知道如何真正与合并的区别我的本地主分支。 git branch
列出了我拥有的所有本地分支,但没有表示要合并到的任何内容。
So, is it just something like git merge master
or git merge origin/master
? What am I missing?
那么,它只是像git merge master
或git merge origin/master
吗?我错过了什么?
采纳答案by Carl Norum
git merge origin/master
should work. Since master
is usually a tracking branch, you could also do git pull
from that branch and it will do a fetch & merge for you.
git merge origin/master
应该管用。由于master
通常是一个跟踪分支,您也可以git pull
从该分支执行,它会为您执行提取和合并。
If you have local changes on your master
that aren't reflected on origin
, you might want git rebase origin/master
to make sure your commits are 'on top'.
如果您的本地更改master
未反映在 上origin
,您可能需要git rebase origin/master
确保您的提交“在最前面”。
回答by John Szakmeister
I typically do this:
我通常这样做:
git merge --ff-only @{u}
Which says, "only do a fast-forward merge from the upstream tracking branch." It's nice because if it fails, then I know I introduced something on master
that is not upstream. I have that aliased to ff
, just to make it easier to type.
其中说,“仅从上游跟踪分支进行快进合并。” 这很好,因为如果它失败了,那么我知道我在master
上游引入了一些东西。我将其别名为ff
,只是为了更容易输入。
If there are changes, and you simply want to merge them, you can do:
如果有更改,并且您只想合并它们,您可以执行以下操作:
git merge @{u}
Which will merge in the upstream branch. However, if you'd like a cleaner history (and avoid the "Merging 'origin/master' into 'master'" commits, then you might want to consider rebasing instead:
这将在上游分支中合并。但是,如果您想要更清晰的历史记录(并避免“将 'origin/master' 合并为 'master'”提交,那么您可能需要考虑改用变基:
git rebase @{u}
Of course, you can you origin/master
instead of @{u}
in any of these examples.
当然,您可以在任何这些示例中origin/master
代替您@{u}
。
回答by maxschlepzig
The command
命令
git pull $some_url
is equivalent to
相当于
git fetch $some_url
git merge FETCH_HEAD
See also the git-pull(1)man page for details, especially the first two paragraphs of the description.
另请参阅git-pull(1)手册页了解详细信息,尤其是描述的前两段。