The best question to help release management - who worked on the critical program/script which is in the release process? This can be found using the git log command.
The most interesting story if someone left the company and need to know what he did in his last commit. Tracking changes all of them done by that particular user.
The git log having many options:
- sorting
- filtering
- output formatting
Let's see in detail by with experimenting each with an example.
How to get the git log in a "Sorting order"?
Here we have a couple of sorted commit history commands.
Using the --pretty value with Oneline to going to give you the log output in simplify format.
git log --pretty=onelineThe output combination of COMMIT_ID COMMIT_MESSAGE | Branch level changes
How to do Filtering while getting the git-log output?
To filter out we can use different options
- author - User name of the commit made by
- date ranges - We have date options with --before and --after where date can be given in "YYYY-MM-DD" format
- regular-expressions - Linux grep like option --grep that takes any text patter to filter
- path - file or directory path can be used to narrow down your log filtering
Find the commit history of a user
Here we have an option to get all changes made by a person/author. If you want to see all commits made by yourself then you can replace the "AUTHOR NAME" with your git user. name what you have configured.
git log --author="AUTHOR NAME"
For example: Find all code changes done by user "Rajasekhar"
Find History in range of dates
You have a choice of selecting range of date before and after dates.
git log --before="date1" --after="date2"
For example: Find all commits between 19th Feb to 26th Feb 2021
Commit History with a regular expression
Git commit history can be extracted with the regular expression that matches to the word or pattern that matches the existing commit messages.git log --grep="PATTERN"For example, find all the 'commit's having an "adding" pattern.
Commit history of a given path
We can use the current work-tree contained in any one of the folders as the path to check the history of that particular directory.git log -- [PATH]
Example for finding the git log history of file of folder as shown below:
git log -- . # current folder git log -- WebLogic/samples # specific directory history git log -- README.md # specific file history
what is happening in this directory? |
Knowing about a particular code file we can use -- then the filename.
For example;
Commit History of a file |
What happened since the date?
Changes from a particular "date" onwards we can get using --since option.
git log --since="YEAR-MM-DD"
For example, find all change that happen since 22-Feb-2021
Since date onwards commit changes |
In most of the real scenarios we need to know the files which are changed recently. This git-log command with the oneline option and abbreviated commit id helps us to have a simple view
git log --pretty=oneline --abbrev-commit
You can use this for more combinations as per your project requirements To get all oneliner logs with short commit id and filtered with specific author changes:
git log --pretty=oneline --abbrev-commit --author "Bhavani"To get all oneline logs with short commit id for all changes made for "WebLogic" pattern matched in the commit messages.
git log --pretty=oneline --abbrev-commit --grep "WebLogic"
Further learning post:
Please write your comments we will workout accordingly and respond to each message within 3 days.
No comments:
Post a Comment