Git - 首先比较本地和远程而不提取? [英] Git - compare local and remote without fetching first?
问题描述
我已搜索过,没有找到此问题的答案。
我有一个应用程序在Heroku上运行。
从我的本地机器我通常实现和只是:
git add。
git commit -m无论什么改变,我知道我可以同时添加和提交...
git push< the-heroku-repo>
然后它会升级,Heroku应用程序中的主分支会更新。到目前为止很好。
现在。我想要有另一台机器,它会自动从Heroku仓库拉出并更新自己。
所以我这样做:
git clone< the-heroku-repo>
这会得到我的应用程序,我可以看到git配置:
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我可以做一个拉:
git pull origin
pre>
或者我可以获取并合并:
git fetch origin
git merge origin / master
我的问题
在上面的fetch和merge之间,我可以通过执行以下操作检查更改:
git log -p master ..origin / master
有一种方法可以找到本地主分支和最新版本在远程Heroku仓库没有提取?只需比较本地和远程并查看更改。我只是找不到正确的方式。
谢谢。
解决方案p>虽然您可以在
origin
存储库中获取有关分支的一些摘要信息:code> git remote show origin
...你需要从
origin
插入你的仓库,以便比较它们。这是git fetch
的作用。当你运行git fetch origin
时,它将默认只更新所谓的远程跟踪分支,如origin / master
。这些只是存储在相应的分支在origin
上次获取。您一直在工作的所有本地分支都不受git fetch
的影响。所以,可以安全地做:git fetch origin
git log -p master..origin / master
...然后如果你很满意,你可以从<$ c> $ c> origin / master 。
我鼓励你不要担心资源(code> git fetch origin 命令中涉及的任何磁盘空间或磁带宽度)。 git有效地只发送完成正在更新的远程跟踪分支所需的对象,除非你有非常大的文件与源代码一起存储,这不应该有太大的区别。此外,如果您不想使用其他存储库中的分支的完整历史记录,则通常很有用,例如,您可以检查该开发历史记录。
I've searched around and found no answer to this question.
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>
Then it goes up and the master branch in the Heroku app is updated. So far so good.
Now. I want to have another machine that will automatically make a pull from the Heroku repo and update itself.
So i do that with:
git clone <the-heroku-repo>
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
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
MY QUESTION
Between the above fetch and merge I can check what are the changes by doing:
git log -p master..origin/master
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.
Thanks.
解决方案Although you can get some summary information about the branches in the
origin
repository using:git remote show origin
... you do need to fetch the branches from
origin
into your repository somehow in order to compare them. This is whatgit fetch
does. When you rungit fetch origin
, it will by default only update the so-called "remote-tracking branches" such asorigin/master
. These just store where the corresponding branch was at inorigin
the last time you fetched. All your local branches that you've been working on are unaffected by thegit fetch
. So, it's safe to do:git fetch origin git log -p master..origin/master
... and then if you're happy with that, you can merge from or rebase onto
origin/master
.
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屋!