Skip to main content

Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » EGit / JGit » Idiomatic way of saving a file
Idiomatic way of saving a file [message #1851478] Wed, 06 April 2022 12:03
Kirill Yankov is currently offline Kirill YankovFriend
Messages: 1
Registered: April 2022
Junior Member
Hello everyone,

I am trying to create a new file (or update an exiting one) with jgit,
so the easiest way is just to first write file contents using standard java IO
File myFile = new File(repository.getDirectory().getParent(), "testfile");
                if(!myFile.createNewFile()) {
                    throw new IOException("Could not create file " + myFile);
//... then write bytes to the file

and then

I am just wondering if the same is possible using only JGit API? Maybe through ObjectInserter (can't find on how to properly do a commit with low level api)?

I am looking for something like
Array[byte] content = ???
String filePath = ???

Git git =;
Repository repo = git.getRepository;
repo.addOrUpdateFileContent(filePath, content);

Thank you for help!
Previous Topic:Idiomatic way to check for bare repos while cloning
Next Topic:JGit exception only when running unit test
Goto Forum:

Current Time: Sat Oct 01 13:46:24 GMT 2022

Powered by FUDForum. Page generated in 0.05634 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top