Commit with specific date using JGit Eclipse

I have investigated the possibilities to control Git from Java.
What I have found is :

  • Using Runtime.getRuntime().exec("git command") – to have Java execute commands with git
  • Using JavaGit API (http://javagit.sourceforge.net/)
    or
    -Using Eclipse JGit API (http://www.jgit.org/)

I tried to write my own Java-wrapper for git with Runtime and ProcessBuilder, but I got problems with the process threads, was waiting for ever for the threads to finish some times.

  • Unable to install EGit plugin on Eclipe Helios
  • Access visualsvn server from eclipse
  • working with bitbucket and native android development
  • .apk includes .git folder
  • Team Synchronizing Perspective for Intellij?
  • How to add an existing git repository (without an eclipse project) into eclipse?
  • I then looked into other solutions with APIs. First I tried JavaGit API, but I can’t get that to work at all.

    Second I tested JGit API, and it is looking great. But I soon find out that I could not set the commit date as I did with my Java-wrapper :

    ProcessBuilder pb = new ProcessBuilder("git", "commit", "--date=" + "\"" + customDateString + "\"", "-m \"" + comment + "\"");
    

    I downloaded the JGit source-code to see if I could implement it, but it was too much to read in and I could not find any issue tracker on Github for JGit to make a suggestion.

    Can someone here help me do this?
    Or tell me where I can write to make a suggestion to the developers?

  • Missing commits after merging to branch with same name as deleted branch
  • Limit refs shown with git log --decorate
  • How do I delete a commit from git history as if it was not at all there?
  • How can I know for which branch a changeset was made at github?
  • What guides or standards do you use for version control in your team?
  • How can I corrupt a Git repository?
  • 2 Solutions collect form web for “Commit with specific date using JGit Eclipse”

    Easy, as you mention, first download jgit:

    C:\> cd C:\Users\VonC\prog\git\
    C:\Users\VonC\prog\git> git clone https://github.com/eclipse/jgit
    C:\Users\VonC\prog\git> cd jgit
    

    Then search for a test (‘tst‘) which involves “authordate“:

    C:\Users\VonC\prog\git\jgit>grep -nRHIi authordate *|grep tst
    
    org.eclipse.jgit.test/tst/org/eclipse/jgit/api/CommitCommandTest.java:446:              final Date authorDate = new Date(1349621117000L);
    

    That means you can have a look at the org.eclipse.jgit.test.tst.org.eclipse/jgit/api.CommitCommandTest, function commitAmendWithoutAuthorShouldSetOriginalAuthorAndAuthorTime():

    You will see how to specify an author and an author date:

    final Date authorDate = new Date(1349621117000L);
    PersonIdent firstAuthor = new PersonIdent(authorName, authorEmail,
       authorDate, TimeZone.getTimeZone("UTC"));
    git.commit().setMessage("initial commit").setAuthor(firstAuthor).call();
    

    Note, as I mention here, the test classes are a good source of documentation/illustration for JGit.

    I had a similar problem some time ago and because JavaGit project seemed a bit dead just forked it, solved some bugs and made some bits going back to work.

    You can try it at the Swiss Army Java Git page and also will be glad to help you.

    Git Baby is a git and github fan, let's start git clone.