git checkout和git status都说我是最新的,但随后git pull进行更改 [英] git checkout and git status both say I am up-to-date, but then git pull pulls changes

查看:172
本文介绍了git checkout和git status都说我是最新的,但随后git pull进行更改的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我在分支"somebranch"上,然后按git checkout master回到主目录.我收到消息在分支主服务器上.您的分支是'origin/master'的最新消息.什么都没提交,工作目录很干净."这与我执行git status时出现的消息相同.

但是接着我做git pull,它将两个更改拉到master.我检查了git log,似乎在3分钟前提交了一次新的提交给master. git status有滞后吗?我只是做了一个git status,它又说我是最新的.我之后立即尝试了另一次拉动,并拉出了一个新分支,但没有更改master-我可以理解,因为git status可能仅检查我当前的分支是否最新.但是有人可以解释git status的工作原理以及为什么出现时滞吗?

问题2:目前我的git工作流程是:

  1. git checkout master
  2. git pull(所以我使用的是最新版本)
    • 现在我想在新分支上处理某些问题
  3. git checkout -b newIssue
    • 解决这个问题
  4. git add .
  5. git commit -m "some msg"

在这一点上,我将推送,代码审查和合并.我不得不做一个变基,因为起源/主人"已经超越了我.如何使分支newIssuemaster保持最新,以便我可以合并?如何从origin/master git pull进入newIssue?

解决方案

关于第一个问题,git status仅查看您自己的存储库,而不查看任何远程存储库.

通常,要查看远程存储库,必须先将其中的所有新内容复制到自己的存储库中.可以执行此命令的命令是git fetch(或者您可以使用git remote update执行相同的操作).

还有git remote show origin,它会咨询远程服务器,并将您对本地的分支机构在哪里"的想法与他们告诉您的内容进行比较.这可能就是您认为使用git status所获得的.但是,它并不是真的很有用,因为您会得到以下两个答案之一:

  • 您当前处于最新状态.没什么可做的了.使用git fetch也不会做任何事情,您将可以完成.
  • 您不是最新的.您必须保持最新状态,以便可以进行基础调整或合并.为此,您必须运行git fetch,它将使您保持最新状态,然后您可以继续进行操作.

将其与只运行git fetch进行比较,它要么不执行任何操作(现在完成),要么对您进行更新(您现在准备进行变基或合并).

so I am on a branch "somebranch," and I go back to master by git checkout master. I get the message "On Branch Master Your branch is up-to-date with 'origin/master'. Nothing to commit, working directory clean." This is the same message that comes up when I do a git status.

But then I do git pull, it pulls two changes to master. I checked git log and it seemed there was a new commit to master 3 minutes ago. Is there a lag with git status? I just did a git status and it again says I am up-to-date. I tried another pull right after and it pulled a new branch but no change to master - this I can understand, as git status probably only checks whether my current branch is up to date. But can someone explain how git status works and why there appears to be a lag?

Question 2: my git workflow at the moment is this:

  1. git checkout master
  2. git pull (so I am on the latest version)
    • now I want to work on some issue on a new branch
  3. git checkout -b newIssue
    • work on the issue, solve it
  4. git add .
  5. git commit -m "some msg"

at this point I would push, code review, and merge. I've had to do a rebase because 'origin/master' had advanced past me. How can I keep my branch newIssue up to date with master so I can just merge? How can I git pull from origin/master into newIssue?

解决方案

Regarding your first question, git status only looks at your own repository, not any remote repositories.

In general, to look at a remote repository, you have to copy anything new in it to your own repository first. The command that does this is git fetch (or you can use git remote update to do the same thing).

There is also git remote show origin, which consults the remote and compares your local idea of "where their branches are" with what they tell you. This may be what you were thinking you were getting with git status. It's not really very useful though, as you get one of two answers:

  • You are currently up to date. There is nothing else to do. Using git fetch would do nothing as well, and you would be done.
  • You are not up to date. You must get up to date so that you can rebase or merge. To do that, you must run git fetch, which will bring you up to date and then you can proceed.

Compare this to simply running git fetch, which either does nothing (you are now done) or updates you (you are now ready to rebase or merge).

这篇关于git checkout和git status都说我是最新的,但随后git pull进行更改的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆