开发者

Git - compare local and remote without fetching first?

开发者 https://www.devze.com 2023-04-08 13:56 出处:网络
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:

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 a开发者_开发问答dd .
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 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

... 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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号