【Git Snippets】View commits [without merge] or [in a specific date range]

201 阅读1分钟

小知识,大挑战!本文正在参与“程序员必备小知识”创作活动。

The Git snippet collection contains a variety of short tips and tricks for all currently maintained versions of git. It includes most commonly-used commands and covers various use-cases in the form of simplified documentation, complete with multiple examples.

Short code snippets for all your development needs.

⭐View a short summary of commits

Prints a short summary of all commits.

  • Use git log --oneline to list a short summary of all commits.
$ git log --oneline

⭐View a short summary of commits without merge commits

Prints a short summary of all commits excluding merge commits.

  • Use git log --oneline --no-merges to list a short summary of all commits without merge commits.
$ git log --oneline --no-merges

Example

All the merge-commits disappear~

$ git-log
*   06b7d6b (dev1) Merge branch 'dev2' into dev1
|\
| | * d93117e (HEAD -> master) Commit from the past!!!
| | * e460e34 (gitee/master) Commit from the past
| | * 26fb3b1 update on 2021.10.11
| | * 8f6a3f2 add LICENSE.
| |/
| *   270d59c (gitee/dev2, dev2) Merge branch 'master' into dev2
| |\
| |/
|/|
* | a8c017f update on 2021-10-09
...

$ git log --oneline --no-merges
d93117e (HEAD -> master) Commit from the past!!!
e460e34 (gitee/master) Commit from the past
26fb3b1 update on 2021.10.11
8f6a3f2 add LICENSE.
a8c017f update on 2021-10-09
...

⭐View commits in a specific date range

Prints all commits in the specified date range.

  • Use git log --since=<date-from> --until=<date-to> to view a log of all commits between <date-from> and <date-on>.
  • You can use only --since=<date-from> to see all commits since a specific date or only --until=<date-on> to view all commits up to a specific date.
  • Use arrow keys to navigate, press Q to exit.
$ git log [--since=<date-from>] [--until=<date-on>]

Example 1

$ git log --since='Apr 1 2021' --until='Apr 4 2021'

Example 2

$ git log --since='2 weeks ago'

🧠Wish you can benefit from this article.
🔥 And welcome to leave your thoughts in the comments section that we can discuss and share ideas with each other.