Skip to main content



      Home
Home » Eclipse Projects » EGit / JGit » Using commit command on JGit cause no diff changes
Using commit command on JGit cause no diff changes [message #1859805] Tue, 27 June 2023 21:15 Go to next message
Eclipse UserFriend
After I use commit command on JGit, it will result in no diff changes.

for example:
-#JAVA_OPTS="${JAVA_OPTS} -XX:NativeMemoryTracking=summary"
+#JAVA_OPTS="${JAVA_OPTS} -XX:NativeMemoryTracking=summary"

The content of the file has no difference but Git shows that this file has been modified. Actually, I commited without any change as soon as I cloned this project. The no diff changes happen in any kinds of files.

Thanks for someone if who can solve this problem.
Re: Using commit command on JGit cause no diff changes [message #1859819 is a reply to message #1859805] Wed, 28 June 2023 14:53 Go to previous messageGo to next message
Eclipse UserFriend
You didn't share the code you are talking about hence it's unclear to me what you tried.
Maybe you missed to add the modified files to the git index using the AddCommand ?

If you are looking for examples refer to the JGit unit tests, e.g.
https://git.eclipse.org/r/plugins/gitiles/jgit/jgit/+/refs/heads/master/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/CommitAndLogCommandTest.java
https://git.eclipse.org/r/plugins/gitiles/jgit/jgit/+/refs/heads/master/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/CommitCommandTest.java
Re: Using commit command on JGit cause no diff changes [message #1859826 is a reply to message #1859819] Wed, 28 June 2023 21:30 Go to previous messageGo to next message
Eclipse UserFriend
Let me describe my work steps:
1.I used CloneCommand to clone a project by this code
try (Git git = Git.cloneRepository()
.setURI(uri)
.setDirectory(new File(BASE_PATH + projectName))
.setCredentialsProvider(provider)
.setCloneSubmodules(true)
.setBranch(RELEASE_BRANCH)
.call()) {
} catch (Exception ex) {
ex.printStackTrace();
}
2. I committed without modifying any code by this code
try (Git git = Git.open(new File(BASE_PATH + projectName))) {
git.add().addFilepattern(".").call();
git.commit().setMessage(DEFAULT_COMMIT_MESSAGE).call();
} catch (Exception ex) {
ex.printStackTrace();
}
3.I used "git diff" commond on git that showed some files has been modified.
For example, in the extraenv.sh, git displays the following code changes:
-#JAVA_OPTS="${JAVA_OPTS} -XX:NativeMemoryTracking=summary"
+#JAVA_OPTS="${JAVA_OPTS} -XX:NativeMemoryTracking=summary"
We can see that the content has no difference. This situation may occur on any kind of files in the project.
Re: Using commit command on JGit cause no diff changes [message #1859853 is a reply to message #1859826] Fri, 30 June 2023 11:43 Go to previous messageGo to next message
Eclipse UserFriend
2. CommitCommand doesn't allow empty commits, so if you didn't add any changes to the git index it should throw an EmptyCommitException.
3. I don't see any diff in the diff you posted, maybe your git line ending configuration changed ?

As I said best start from the mentioned JGit unit tests

Which version of JGit and git are you using ?
Re: Using commit command on JGit cause no diff changes [message #1859913 is a reply to message #1859853] Wed, 05 July 2023 04:42 Go to previous messageGo to next message
Eclipse UserFriend
I am using the following version:
<dependency>
<groupId>org.eclipse.jgit</groupId>
<artifactId>org.eclipse.jgit</artifactId>
<version>4.6.0.201612231935-r</version>
</dependency>
<dependency>
<groupId>org.eclipse.jgit</groupId>
<artifactId>org.eclipse.jgit.ssh.apache</artifactId>
<version>5.10.0.202012080955-r</version>
</dependency>

I have ruled out that it was caused by CloneCommand, and it can be almostly determined that it was caused by the CommitCommand
Re: Using commit command on JGit cause no diff changes [message #1859957 is a reply to message #1859913] Thu, 06 July 2023 15:42 Go to previous messageGo to next message
Eclipse UserFriend
This mixture of JGit 4.6 and the Apache MINA sshd 5.10 transport doesn't make sense. Also, JGit 4.6 is very old. Update to a newer version. Use 6.6 for both if you're using Java 11 or newer, otherwise use 5.13 for both.
Re: Using commit command on JGit cause no diff changes [message #1859961 is a reply to message #1859957] Thu, 06 July 2023 23:09 Go to previous message
Eclipse UserFriend
When I use JGit 5.15 instead of the old version, this problem will no longer occur. Thank you.
Previous Topic:Pull doesnt work in Git Perpective
Next Topic:Create a main branch, not master
Goto Forum:
  


Current Time: Thu May 22 05:58:29 EDT 2025

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

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

Back to the top