Git - 比较本地和远程而不先获取? [英] Git - compare local and remote without fetching first?

查看:16
本文介绍了Git - 比较本地和远程而不先获取?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我四处寻找,没有找到这个问题的答案.

I've searched around and found no answer to this question.

我有一个在 Heroku 上运行的应用程序.我通常从我的本地机器上实现并且只是:

I have an app running on Heroku. From my local machine I typically implement and just:

git add .
git commit -m "whatever change, I know I can add and commit at the same time..."
git push <the-heroku-repo>

然后它上升并更新 Heroku 应用程序中的主分支.到目前为止一切顺利.

Then it goes up and the master branch in the Heroku app is updated. So far so good.

现在.我想要另一台机器,它会自动从 Heroku 存储库中提取并更新自身.

Now. I want to have another machine that will automatically make a pull from the Heroku repo and update itself.

所以我这样做:

git clone <the-heroku-repo>

这得到了我的应用程序,我可以看到 git 配置:

That gets me the app and I can see the git config with this:

core.repositoryformatversion=0
core.filemode=true
core.bare=false
core.logallrefupdates=true
remote.origin.fetch=+refs/heads/*:refs/remotes/origin/*
remote.origin.url=git@heroku.com:theapp.git
branch.master.remote=origin
branch.master.merge=refs/heads/master

要更新这个新的 repo,我只需拉一下即可:

To update this new repo I can do just a pull:

git pull origin

或者我可以获取并合并:

Or I could fetch and merge:

git fetch origin
git merge origin/master

我的问题

在上述提取和合并之间,我可以通过以下方式检查更改内容:

Between the above fetch and merge I can check what are the changes by doing:

git log -p master..origin/master

有没有办法找到本地 master 分支和远程 Heroku repo 中最新版本之间的差异而无需之前获取?只需比较本地和远程并查看更改.我就是找不到合适的方法.

Is there a way to find the differences between the local master branch and the latest version in the remote Heroku repo without fetching before? Just compare the local and remote and see the changes. I just can't find the proper way.

谢谢.

推荐答案

虽然您可以使用以下方法获取有关 origin 存储库中分支的一些摘要信息:

Although you can get some summary information about the branches in the origin repository using:

git remote show origin

...您确实需要以某种方式将分支从 origin 提取到您的存储库中以便比较它们.这就是 git fetch 所做的.当你运行 git fetch origin 时,它默认只会更新所谓的远程跟踪分支",例如 origin/master.这些只是存储您上次获取时 origin 中相应分支的位置.您一直在处理的所有本地分支都不受 git fetch 的影响.所以,这样做是安全的:

... you do need to fetch the branches from origin into your repository somehow in order to compare them. This is what git fetch does. When you run git fetch origin, it will by default only update the so-called "remote-tracking branches" such as origin/master. These just store where the corresponding branch was at in origin the last time you fetched. All your local branches that you've been working on are unaffected by the git fetch. So, it's safe to do:

git fetch origin
git log -p master..origin/master

...如果您对此感到满意,您可以从 origin/master 进行合并或变基.

... and then if you're happy with that, you can merge from or rebase onto origin/master.

我建议您不要担心 git fetch origin 命令所涉及的资源(磁盘空间或带宽).git 有效地仅发送完成正在更新的远程跟踪分支所必需的对象,除非您的源代码存储了异常大的文件,否则这不会有太大区别.此外,即使您不打算使用来自其他存储库的分支的完整历史记录,也通常很有用,例如,您可以检查该开发历史记录.

I would encourage you not to worry about the resources (either disk space or bandwidth) involved in the git fetch origin command. git efficiently sends just the objects that are necessary to complete the remote-tracking branches that are being updated, and unless you have unusually large files stored with your source code, this shouldn't make much of a difference. In addition, it's frequently useful to have the complete history of the branches from the other repository available even if you don't plan to use them, for example so you can examine that development history.

这篇关于Git - 比较本地和远程而不先获取?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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