list fail to detect remote / origin changes?

I'm trying to build a reliable "repo ahead and behind" signal for my bash prompt. Despite reading source code for many git prompts (shell, python scripts) and reading many stack overflow answers, I could not figure out why comparing

$ git rev-list HEAD..origin/master

did not actually compare master at the origin. Figured it out, so I decided to ask this question and answer it so it's not buried and will immediately answer someone else's similar question.


It finally dawned on me that origin/master is just a local "pointer", which makes sense with git's distributed nature. It really threw me until I remembered this. Almost none of the answers about comparing local and remote repos comes right out and says that you must do a fetch. Finally found one. Anyway, I have parrt's git bash prompt working in a very reliable way. To determine whether your repository is behind the origin, do this:

$ git fetch origin mybranch
$ git rev-list HEAD..origin/mybranch

This is expensive so my bash prompt script does it every 30 minutes to see if I'm behind remote repo.

链接地址: http://www.djcxy.com/p/7570.html

上一篇: Git在合并时采取他们或我的文件

下一篇: 列表无法检测远程/原点更改?