Чтобы получить количество строк, измененных в коммите Git, вы можете использовать различные методы. Вот несколько примеров на разных языках программирования:
-
Использование командной строки Git:
git show --stat <commit_hash>
Эта команда отобразит сведения о фиксации, включая количество измененных строк.
-
Использование GitPython (библиотека Python для Git):
import git repo = git.Repo('<path_to_repo>') commit = repo.commit('<commit_hash>') lines_changed = commit.stats.total['lines'] print(lines_changed)
-
Использование JGit (библиотеки Java для Git):
import org.eclipse.jgit.api.Git; import org.eclipse.jgit.api.errors.GitAPIException; import org.eclipse.jgit.lib.Repository; import org.eclipse.jgit.revwalk.RevCommit; import org.eclipse.jgit.revwalk.RevWalk; import java.io.IOException; public class GitExample { public static void main(String[] args) throws IOException, GitAPIException { try (Repository repository = Git.open(new File("<path_to_repo>")).getRepository()) { try (RevWalk revWalk = new RevWalk(repository)) { RevCommit commit = revWalk.parseCommit(repository.resolve("<commit_hash>")); int linesChanged = commit.getLinesChanged(); System.out.println(linesChanged); } } } }
-
Использование libgit2 (библиотека C/C++ для Git):
#include <stdio.h> #include <git2.h> int main() { git_libgit2_init(); git_repository* repo; git_repository_open(&repo, "<path_to_repo>"); git_oid commit_oid; git_oid_fromstr(&commit_oid, "<commit_hash>"); git_commit* commit; git_commit_lookup(&commit, repo, &commit_oid); size_t lines_changed = git_commit_stats(commit)->files_changed; printf("%zu\n", lines_changed); git_commit_free(commit); git_repository_free(repo); git_libgit2_shutdown(); return 0; }