{"id":21822210,"url":"https://github.com/ethiclab/git4j","last_synced_at":"2026-05-17T02:11:36.597Z","repository":{"id":95637600,"uuid":"95151938","full_name":"ethiclab/git4j","owner":"ethiclab","description":"git4j is an attempt to learn how git works by implementing some parts of it.","archived":false,"fork":false,"pushed_at":"2021-01-27T11:13:14.000Z","size":22,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-01-26T07:41:25.002Z","etag":null,"topics":["from-scratch","git","java","learn","tdd","test"],"latest_commit_sha":null,"homepage":null,"language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ethiclab.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2017-06-22T20:02:12.000Z","updated_at":"2021-06-23T17:59:27.000Z","dependencies_parsed_at":"2023-06-08T08:00:42.863Z","dependency_job_id":null,"html_url":"https://github.com/ethiclab/git4j","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ethiclab%2Fgit4j","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ethiclab%2Fgit4j/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ethiclab%2Fgit4j/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ethiclab%2Fgit4j/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ethiclab","download_url":"https://codeload.github.com/ethiclab/git4j/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244787119,"owners_count":20510064,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["from-scratch","git","java","learn","tdd","test"],"created_at":"2024-11-27T17:13:42.472Z","updated_at":"2026-05-17T02:11:31.572Z","avatar_url":"https://github.com/ethiclab.png","language":"Java","funding_links":[],"categories":[],"sub_categories":[],"readme":"# git4j\n\n[![Build Status](https://travis-ci.org/ethiclab/git4j.svg?branch=master)](https://travis-ci.org/ethiclab/git4j)\n\n[![codecov](https://codecov.io/gh/ethiclab/git4j/branch/master/graph/badge.svg)](https://codecov.io/gh/ethiclab/git4j)\n\ngit4j is an attempt to learn how git works by implementing some parts of it.\n\n## Create Root Tree\n\nHere we create an initial tree at root leve; with a file named pippo with the content \"Hello World!\\n\\n\"\n\n```java\n    private GitTreeEntry createInitialTree() {\n        List\u003cGitTreeEntry\u003e objects = new ArrayList\u003c\u003e();\n        objects.add(createFileEntry(\"pippo\", \"Hello World!\\n\\n\"));\n        return new GitTreeEntry(objects);\n    }\n    \n    @Test\n    public void testTreeWith1Item() {\n        assertThat(g.binaryToHex(g.getTreeSha(createInitialTree())))\n                .isEqualTo(\"132bfb311556de7c60c34ef3d450c9e8bcc6310b\");\n    }\n```\n\n## Create Initial Commit\n\nHere we create a commit with a reference to the tree created in the previous example.\n\n```java\n        /**\n         * tree 132bfb311556de7c60c34ef3d450c9e8bcc6310b\n         * author Montoya Edu \u003cmontoya.edu@gmail.com\u003e 1496830486 +0200\n         * committer Montoya Edu \u003cmontoya.edu@gmail.com\u003e 1496830486 +0200\n         *\n         * Add file.\n         *\n         */\n         \n        Git git = new Git();\n\n        GitCommit c = new GitCommit();\n        c.setMessage(\"Add file.\");\n        c.setCommitter(\"Montoya Edu \u003cmontoya.edu@gmail.com\u003e\");\n        c.setAuthor(\"Montoya Edu \u003cmontoya.edu@gmail.com\u003e\");\n        \n        Calendar calendar = g.getCalendar(\"Europe/Rome\");\n        calendar.setTimeInMillis(1496830486);\n        \n        c.setAuthoringDate(calendar.getTime());\n        c.setCommitDate(calendar.getTime());\n        c.setAuthoringTimezone(\"Europe/Rome\");\n        c.setCommitTimezone(\"Europe/Rome\");\n        c.setTree(\"132bfb311556de7c60c34ef3d450c9e8bcc6310b\");\n        \n        byte[] bytes = g.serialize(c);\n        \n        byte[] compressed = g.compress(bytes);\n        \n        String sha = g.binaryToHex(g.getSha(c));\n        \n        // now that we have the SHA1 string, and the compressed bytes, we can store it:\n        // on the filesystem, as git normally does, or\n        // you can choose the kind persistence layer you want to use for your needs.\n```\n\n## Further details\n\nLook for file [GitTest.java](src/test/java/it/ethiclab/git4j/GitTest.java)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fethiclab%2Fgit4j","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fethiclab%2Fgit4j","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fethiclab%2Fgit4j/lists"}