简体   繁体   English

当我在开发分支中执行git pull origin master时会发生什么?

[英]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 fetchgit 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.

相关问题 Git 将 origin/master 分支拉到 local/master,当在 local/develop - Git pull origin/master branch to local/master, when in local/develop 当我从一个功能分支中“拉出--rebase origin development”时会发生什么? - What happens when I 'git pull --rebase origin development' from within a feature branch? 当我从功能分支执行“git pull origin master --rebase”时,我收到过时的传入代码 - When I do “git pull origin master --rebase” from a feature branch, I receive outdated incoming code 当我从有新文件的本地分支进行git fetch和git checkout origin / branch时,实际会发生什么? - What happens actually when I do git fetch and git checkout origin/branch from a local branch where new files are there? Git-拉取请求后,我的本地master分支会怎样? 如何管理多个进行中的分支? - Git - What happens to my local master branch after a pull request? How do I manage multiple in progress branches? 当我在master分支上时从另一个分支拉出时会发生什么 - What happens when I pull from a different branch while I am on the master branch 我做了一个 git pull origin<featurename> 在开发这不是我想做的 - I did a git pull origin <featurename> on develop which is not what I wanted to do 使用git pull -a origin开发时-a标志意味着什么? - What does the -a flag mean when using git pull -a origin develop? Git拉起源 <branch> 覆盖大师? - Git pull origin <branch> overwrites master? Git将master拉入原点的远程分支 - Git pull master into remote branch on origin
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM