0

We are using jgit to store versions for some internal files and i would like to allow only a limited number of versions per file. Currently I can add an unlimited number of commits per file using:

git.add()
        .addFilepattern(fileName + ".yaml")
        .call();
git.commit()
        .setMessage(comment)
        .setAuthor((String)context.get("userName"),(String)context.get("userName")+"@xxx.ch")
        .call();

I would like to check if the number of git versions per file is greater of n and in that case squash the n-version and n+1 version or just delete the n+1 version. How can I check in jGit if the number of versions for a specific file in the repo is greater of n and squash two versions or the delete the n+1 version? Is there maybe a better way to do this?

UPDATE:

Say I allow 5 versions for each file in the git repo and I have the following entries in the git reflog:

A-----B------C------D------E------F------G------H------I

The specific file has the following git log entires:

B-----C------E------F------G------H

I can envision two options: One option: "squash" commits G and H to Z. Second option: "delete" commit H

I am working only in one branch (master) on a local machine. I reviewed the answer to this question but I am still not sure how can I do this using `jGit.

Ana Sustic
  • 425
  • 2
  • 17
  • 1
    That is not something that the Git Version Control can do out of the box, each commit is based on all previous commits, each change to a file on all previous changes, so you would need to use some rebase-like approach to rewrite histoy all the time, likely rather complicated to do... – centic Mar 28 '21 at 06:24
  • Thanks @centic Can I rebase with jGit one or more commits into the same branch? Please see my upddated question above. – Ana Sustic Mar 29 '21 at 12:29

1 Answers1

-1

We decided not to rewrite the history of files in the repo.

Ana Sustic
  • 425
  • 2
  • 17