开发者

How to get the same push output using a date range in Git?

开发者 https://www.devze.com 2023-03-04 07:03 出处:网络
I like how git开发者_运维知识库 shows how much code I pushed to the server [1] , is there a way to get that input date ranges or commits?

I like how git开发者_运维知识库 shows how much code I pushed to the server [1] , is there a way to get that input date ranges or commits?

[1]: 6 files changed, 575 insertions(+), 3 deletions(-)


The primary ways to get this kind of information are the --shortstat, --stat and --numstat options which can be passed to the diffcore machinery, e.g. through git-diff and git-log.

In your case, it sounds like you want the --shortstat option, which only gives the summary line, not the pretty information for each file like you see after a pull given by --stat. The last one, --numstat, gives the same file-by-file information in a more machine-readable format.

To apply this to a commit range, just use git diff --shortstat A B, where A and B are the commits you want to compare.

To get that same information for each individual commit in the range, instead of all lumped together, use git log --shortstat A..B.

If you want to do this by date, you have a couple options:

  • Specify a single commit using the form <branch>@{<date>}. Be aware, though, that this gives the position of that branch on that given date. This is fine if it's a long-lived local branch, but if it didn't exist yet on that date, or it's a remote branch that moves in big leaps when you fetch, that might not be what you want.

  • Use the --since and --until options for git log. This does mean that you'll have to use two steps if you want the overall summary - one to figure out the commits on each end of the range, and one to actually do the diff.

For more information on how to specify commits see man gitrevisions.


git push origin your_branch --verbose

This should give you a hash range in the output. Now you can do:

git log sha1A..sha1B

If you want to experiment with this first add --dry-run to the push - the push won't actually happen.

But before you push, you can also try:

git log origin/your_branch..your_branch

This will show you the commits you will push. If your_branch is already checked out, you can just issue:

git log origin/your_branch..

This will implicitly match the range to HEAD which is your branch.

hope this helps.

0

精彩评论

暂无评论...
验证码 换一张
取 消