Check if pull needed in Git

后端 未结 24 1332
忘了有多久
忘了有多久 2020-11-22 13:34

How do I check whether the remote repository has changed and I need to pull?

Now I use this simple script:

git pull --dry-run | grep -q -v \'Already          


        
24条回答
  •  花落未央
    2020-11-22 14:03

    I would do the way suggested by brool. The following one-line script takes the SHA1 of your last commited version and compares it to the one of the remote origin, and pull changes only if they differ. And it's even more light-weight of the solutions based on git pull or git fetch.

    [ `git log --pretty=%H ...refs/heads/master^` != `git ls-remote origin
    -h refs/heads/master |cut -f1` ] && git pull
    

提交回复
热议问题