开发者

Git: How to check for remote changes within a directory

开发者 https://www.devze.com 2023-01-24 06:05 出处:网络
Given that Git is very SHA-1 friendly, I would surmise that it is possible to easily check for this scenario:

Given that Git is very SHA-1 friendly, I would surmise that it is possible to easily check for this scenario:

-I have a repo with a directory foo/ somewhere within it. -Someone on some other computer makes a change to foo's contents (including nested subdirectories), and pushes the change to the repo.

My guess is that I will have to do a fetch and check if there is some difference between th开发者_JS百科e SHA-1 for my directory and the SHA-1 of the remote directory, but I don't know how to do this.


you can simply use git diff --quiet and check its exit code:

git fetch # get latest code from upstream
git diff --quiet master..origin/master -- foo/ || echo 'directory differ'

diff --quiet will exit with 1 when there are differences and exit with an error code of 0 the objects (blob or tree) are identical

0

精彩评论

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