Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to track new commits with Git?

Tags:

git

I'm writing an external Git plugin. It should process commits in Git and create some entity in another system if commit contains some text. Note that I want to search through all entire repository, not some branch. Also I have storage in my plugin, so I can store some revision SHA for example

I clone Git repository locally and fetch it periodically. During fetch I want to discover which new commits were added since last synchronization. Is there any easy way to do this?

One solution is to create local branches, and after fetch discover the difference between local branch and origin branch. But what to do if there was forced update on remote branch? In that case difference can be huge, and the same commits can be processed twice. Also if I will use local branches solution, and new branch is added on remote server, I definitely do not want to process all commits in new branch, just the unique one.

Git 'fetch' command definitely can do this. So I hope there is some easy way.

like image 569
struhtanov Avatar asked Nov 11 '22 22:11

struhtanov


1 Answers

  • If you have only one clone, you can add a git notes to remember the HEAD SHA1 you just fetched
  • If you can have two clones:
    • you fetch in the first
    • you compare between what you have fetch and you second cloned repo
    • once you have compared the log, you push to that second repo (which act as a memento for keeping the state of your last push)
like image 100
VonC Avatar answered Nov 15 '22 04:11

VonC