Showing new commits in remote Git repository
we have a Git remote repository (in a way, our "central" repository) on the server of our site and the site is run off that repository. Just pushing to the repository does not update the site, we have to run a little script on the 开发者_如何学Goserver first.
Now I want to display a little warning when there are new commits that haven't been applied yet. Which Git command can I use to find out whether there are commits that have been pushed but not yet applied?
You could store the SHA of the commit that is currently "live" on the site, and then compare it with the SHA returned by git rev-parse <name of remote>/master
.
(You may need to run a git fetch <name of remote>
first to make sure you have the latest info for that remote.)
Rather than warning users about the web view of the repo not being up to date, why not keep it up to date all the time? The default behavior (when enabled) of the post-update hook should do what you want.
If the "new commits" for submodules, I think you can run git submodule sync
and git submodule update
.
精彩评论