git status vs fetch(或pull):如何知道什么是“最新”意味着(不改变任何东西) [英] git status vs fetch (or pull): How to know what "up-to-date" means (without changing anything)

查看:155
本文介绍了git status vs fetch(或pull):如何知道什么是“最新”意味着(不改变任何东西)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我做了一个 git status ,它表示

您的分支是最新的'origin / master '。



但是我做了一个 git pull ,突然间它说: >
14个文件已更改,...



我觉得我被骗了。我怀疑git没有损坏。这意味着我不明白的东西。



我做了一些阅读这里这里,并学习两种非破坏性的方法来问我是否会 m最新



git status -uno



git fetch --dry-run



由于 fetch pull 的一部分我假设这两个人不会像过去两个人一样不同意。



什么是根本上混淆我认为'最新'的含义是:嘿,我们已经比较了这个存储库的两个副本(主分支),它们是相同的



好的,但如果我可以用两种不同的方式提出问题并得到两个不同的答案,那么每个问题都是关于比较两个不同的警察ies然后并不意味着至少有三个版本的存储库?



如:

< blockquote>

A == B!= C


我知道有一个远程副本>
我知道有我的本地副本



第三件事是什么?

当Git说你的分支是最新的'origin / master'它比较你的本地 master 分支对远程跟踪分支调用 origin / master 。此跟踪分支也存在于本地,并且是更新本地分支时实际使用的内容。当你做一个 git fetch 时,所有的远程追踪分支都会得到更新。



你的本地 master 分支是跟踪分支的当前分支,但这并不意味着本地分支对于存储库中实际的 master 分支是最新的。如果您在初次调用 git status 之后完成了 git fetch ,则会看到一条消息,指出您的本地 master 分支是后面 origin / master 。做一个 git pull 意味着更新跟踪分支 origin / master ,然后将它合并到你的本地分支以同步所有内容。



以下是一个简单的图表,显示从远程到本地分支的信息流:

 远程主(回购) - >起源/主人(本地跟踪分支) - > master(本地分支)


I do a git status and it says
Your branch is up-to-date with 'origin/master'.

But I do a git pull anyway and suddenly it says
14 files changed, ...

And I feel like I've been lied to. I suspect git isn't broken. Which must mean I don't understand something.

I do a bit of reading here and here and learn of two non destructive ways to ask if I'm up to date

git status -uno

git fetch --dry-run

Since fetch is part of pull I assume these two will disagree the same way the last two did.

What's fundamentally confusing me is I think of 'up-to-date' as meaning: "hey we've compared two copies of this repository (the master branch) and they're the same"

Ok fine, but if I can ask the question two different ways and get two different answers, when each question is about comparing two different copies then doesn't that mean there have to be at least three copies of the repository?

As in:

A == B != C

I know there is a remote copy of master
I know there is my local copy of master

What the heck is this third thing?

解决方案

When Git says Your branch is up-to-date with 'origin/master' it is comparing your local master branch against the remote tracking branch called origin/master. This tracking branch also exists locally and is what is actually used when you update your local branch. And when you do a git fetch, all the remote tracking branches get updated.

Your local master branch was current with the tracking branch, but this does not mean that the local branch is current with the actual master branch on the repository. Had you done a git fetch after your initial call to git status, you would have a seen a message saying that your local master branch was "behind" origin/master. Doing a git pull means updating the tracking branch origin/master, and then merging that into your local branch to sync everything.

Here is a simplistic diagram showing the flow of information from the remote to your local branch:

remote master (repo) --> origin/master (local tracking branch) --> master (local branch)

这篇关于git status vs fetch(或pull):如何知道什么是“最新”意味着(不改变任何东西)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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