3

We have an application that is monitoring Git repositories using JGit. One of the current requirement is monitoring only files that have been created/modified after the branch was created (at least in the initial phase).

The idea was to get the time when the branch was created and synchronize only files which have been created later.

My question is if you know of any good idea to get time when the branch was created? Or maybe someone could suggest some other way to solve this issue based on their experience with JGit.

Rüdiger Herrmann
  • 18,905
  • 11
  • 53
  • 72
  • A branch (if you disregard its reflog, which is purely local) doesn't keep track of when it was created. Relevant: https://stackoverflow.com/a/24940131/2541573 – jub0bs Apr 17 '18 at 14:59

1 Answers1

3

In git you cant know when a branch was created.
branch is only a pointer to a given commit.

What you can do you have to mark the branch in some way.

How can you mark branches?

Since you don't have a way to mark branches you can either tag the branch with a git tag or add a note using git notes

git tag will add a new tag to any given commit and you can add more than one tag to any commit.

git notes add notes to any git commit. The notes are not part of the commit and can be removed or modified without having any effect on the SHA-1

You can use git merge-base to find out when the branch was last updated, not when it was created

Yassin Hajaj
  • 20,020
  • 9
  • 41
  • 81
CodeWizard
  • 92,491
  • 19
  • 110
  • 133