Check if pull needed in Git

后端 未结 24 1606
忘了有多久
忘了有多久 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:11

    git ls-remote | cut -f1 | git cat-file --batch-check >&-
    

    will list everything referenced in any remote that isn't in your repo. To catch remote ref changes to things you already had (e.g. resets to previous commits) takes a little more:

    git pack-refs --all
    mine=`mktemp`
    sed '/^#/d;/^^/{G;s/.\(.*\)\n.* \(.*\)/\1 \2^{}/;};h' .git/packed-refs | sort -k2 >$mine
    for r in `git remote`; do 
        echo Checking $r ...
        git ls-remote $r | sort -k2 | diff -b - $mine | grep ^\<
    done
    

提交回复
热议问题