How to get Diff from two files using git4idea dependency

已回答

As straightforward as this question may appear I haven't found a way to get a simple Diff between two files using git4idea. What i'm trying to achieve is:

VirtualFile root = gitRepository.getRoot();
ChangeListManager changeListManager = ChangeListManager.getInstance(project);
for (Change change : changeListManager.getChangesIn(root)) {
	// create some form of Diff that can be later analysed by AI
}

Can anyone help?

1

Hi Michal,

Please clarify your use case. What does it mean to get a diff from two files in the Git context? Or do you want to compare two local files, not in the VCS context?

1

I'm working on a small project where you can send the information about changes made in a project to a Large Language Model and it returns the commit message for those changes. I'm currently able to get the content of each file before the changes has been made through change.getBeforeRevision().getContent() and after the changes has been made through change.getAfterRevision().getContent(). But sending the content of the whole file twice is very inefficient. Therefore I need some representation of only the changes. I believe something like this must already exist in the git4idea library but I cannot find any explicit information or documentation about it. 

For example:

The IDE can tell the difference between those two files. But how to access this information programmatically?

0

请先登录再写评论。