获取后 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

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

Git merge after fetch - how, exactly?

gitgit-mergegit-fetch

提问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 branchlists 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 masteror git merge origin/master? What am I missing?

那么,它只是像git merge mastergit merge origin/master吗?我错过了什么?

采纳答案by Carl Norum

git merge origin/mastershould work. Since masteris usually a tracking branch, you could also do git pullfrom 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 masterthat aren't reflected on origin, you might want git rebase origin/masterto 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 masterthat 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/masterinstead 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)手册页了解详细信息,尤其是描述的前两段。