Is there any easy way to calculate the number of lines changed between two commits in git? I know I can do a git diff
, and count the lines, but this seems tedious. I'd also like to know how I can do this, including only my own commits in the linecounts.
相关问题
- Why does recursive submodule update from github fa
- Extended message for commit via Visual Studio Code
- Emacs shell: save commit message
- Can I organize Git submodules in a flat hierarchy?
- Upload file > 25 MB on Github
相关文章
- 请教Git如何克隆本地库?
- GitHub:Enterprise post-receive hook
- Git Clone Fails: Server Certificate Verification F
- SSIS solution on GIT?
- Is there a version control system abstraction for
- ssh: Could not resolve hostname git: Name or servi
- Cannot commit changes with gitextensions
- git: retry if http request failed
EDIT: You have to specify the commits as well (without parameters it compares the working directory against the index). E.g.
to compare the parent of
HEAD
withHEAD
.Another way to get all change log in a specified period of time
Output:
With a long output content, you can export to file for more readable
You want the
--stat
option ofgit diff
, or if you're looking to parse this in a script, the--numstat
option.--stat
produces the human-readable output you're used to seeing after merges;--numstat
produces a nice table layout that scripts can easily interpret.I somehow missed that you were looking to do this on multiple commits at the same time - that's a task for
git log
. Ron DeVera touches on this, but you can actually do a lot more than what he mentions. Sincegit log
internally calls the diff machinery in order to print requested information, you can give it any of the diff stat options - not just--shortstat
. What you likely want to use is:but you can use
--numstat
or--shortstat
as well.git log
can also select commits in a variety other ways - have a look at the documentation. You might be interested in things like--since
(rather than specifying commit ranges, just select commits since last week) and--no-merges
(merge commits don't actually introduce changes), as well as the pretty output options (--pretty=oneline, short, medium, full...
).Here's a one-liner to get total changes instead of per-commit changes from git log (change the commit selection options as desired - this is commits by you, from commit1 to commit2):
(you have to let git log print some identifying information about the commit; I arbitrarily chose the hash, then used awk to only pick out the lines with three fields, which are the ones with the stat information)
gives you just the number of lines changed and added. This only works with unstaged changes. To compare against a branch:
Though all above answers are correct, below one is handy to use if you need count of last many commits
below one is to get count of last 5 commits
git diff $(git log -5 --pretty=format:"%h" | tail -1) --shortstat
to get count of last 10 commits
git diff $(git log -10 --pretty=format:"%h" | tail -1) --shortstat
generic - change N with count of last many commits you need
git diff $(git log -N --pretty=format:"%h" | tail -1) --shortstat
to get count of all commits since start
git diff $(git log --pretty=format:"%h" | tail -1) --shortstat
For the lazy, use
git log --stat
.