![]() The result is an output that might look something like this: 4b7e32d Add new featureĩ files changed, 122 insertions(+), 77 deletions(-)Ģ files changed, 14 insertions(+), 8 deletions(-)ģ files changed, 30 insertions(+) Example If you’re only interested in the number of lines changed, you might find it useful to also use the -oneline option. This option will display a summary of the changes made in each commit, including the number of files modified, the number of lines added, and the number of lines removed. To inspect the number of changed lines in individual commits between a range of commits, you can use git log the -shortstat option. The problem with this approach is that it shows the absolute difference but tells nothing about the individual commits.įor example, if you have added some 1000 lines in one commit and then later removed 1000 different lines from the same file the git diff -shortstat shows there are 0 insertions between the commits. The previous example showed you how to get the number of changed files between two commits by running git diff with the -shortstat option. Number of Changed Lines with ‘git log –shortstat’ So indeed, there are now 5 lines instead of 2 which means there are 3 additions in total. This is indeed the case with my example project because now the text file looks like this.Īnd after the commit accf83f, the file looked like this: This suggests one file only has changed and there are three total insertions to the file. Now let’s run git diff with the -shortstat option between the first and the last commit: $ git diff -shortstat accf83f 4f0338a Here’s the commit history of an example project where I modify a test.txt file contents in three different commits: ![]() Let’s see a concrete example to support understanding. If a file was added or deleted between the two commits, it will not be included in the output of the git diff command. Note: The git diff command only shows the number of changed lines for files that are part of the Git repository. This output indicates that 7 files were modified, with 65 lines added and 33 lines removed. The output of the git diff command will show the number of changed lines between the two commits.įor example, the output might look something like this: 7 files changed, 65 insertions(+), 33 deletions(-).Replace and with the commit hashes for the two commits that you want to compare (or use the HEAD~N to refer to earlier commits).The syntax for this command is as follows: Use the git diff command to compare the two commits.You can use the git log command to view a list of recent commits and their corresponding commit hashes. Identify the two commits that you want to compare.To use git diff to calculate the number of changed lines between two commits: Let’s jump into it! Number of Changed Lines with ‘git diff –shortstat’ ![]() You will learn how to get the info for individual commits in a range of commits as well as the total number of changed lines. This comprehensive guide teaches you how to view the number of changed lines between commits. ![]() To view the number of lines changed between multiple commits individually, run git log with the -shortstat option. To view the number of changed lines, use the -shortstat option. It shows the total differences between two commits by listing the files that have been modified, added, or deleted. To calculate the number of changed lines between two commits in Git, use the git diff command.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |