[英]What happens when I do git pull origin master in the develop branch?
Let's say I have a private topic branch called develop with 2 commits ahead of master. 假设我有一个名为develop的私有主题分支,在master之前有2次提交。
What does git pull origin master
do? git pull origin master
做什么?
Pull everything from the remote master in the local develop and merge it? 从本地开发中的远程主机拉出所有内容并合并它? Pull everything in the local master branch and merge it?
拉出本地主分支中的所有内容并合并它?
And is there a way to update master from develop without git checkout master
first? 并且有没有办法从没有
git checkout master
开发更新master?
git pull origin master
pulls the master branch from the remote called origin into your current branch. git pull origin master
将master分支从远程调用origin拉入当前分支。 It only affects your current branch, not your local master branch. 它只影响您当前的分支,而不影响您的本地主分支。
It'll give you history looking something like this: 它会给你历史看起来像这样:
- x - x - x - x (develop)
\ /
x - x - x (origin/master)
Your local master branch is irrelevant in this. 您当地的主分支机构与此无关。
git pull
is essentially a combination of git fetch
and git merge
; git pull
本质上是git fetch
和git merge
的组合; it fetches the remote branch then merges it into your current branch. 它获取远程分支,然后将其合并到当前分支中。 It's a merge like any other;
这是一个像其他任何一样的合并; it doesn't do anything magical.
它没有做任何神奇的事情。
If you want to update your local master branch, you have no choice but to check it out. 如果您想更新本地主分支,您别无选择,只能查看它。 It's impossible to merge into a branch that's not checked out, because Git needs a work tree in order to perform the merge.
合并到未检出的分支是不可能的,因为Git需要工作树才能执行合并。 (In particular, it's absolutely necessary in order to report merge conflicts and allow you to resolve them.)
(特别是,为了报告合并冲突并允许您解决它们,这是绝对必要的。)
If you happen to know that pulling into master would be a fast-forward (ie you have no commits in your local master branch that aren't in origin's master) you can work around, as described in this answer . 如果你碰巧知道拉入master将是一个快进(即你没有在你的本地主分支中提交不在源代码中的提交)你可以解决, 如本答案所述 。
Once you commit you changes into your branch by using 提交后,您可以使用更改进入分支
git add -A
git commit -m <message>
You can then do: 然后你可以这样做:
git pull origin master
into your branch and that will keep your commits on top of the master pull. 进入你的分支,这将使你的提交保持在主拉。 Your branch will now be even with master + your commits on top.
您的分支现在甚至可以使用master +您的提交。 So, you can now do:
所以,你现在可以这样做:
git push
and git will push your changes, together with the master commits into you branch. 并且git会将您的更改与主提交一起推送到您的分支。 You can easily then merge that into master on Github.
您可以轻松地将其合并到Github上的master中。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.