Git & GitHub - Inspect & Compare branches
In the previous article, we discussed how to create and merge branches in Git. In this article, we will see how to inspect and compare the commits made in different branches.
Git Log
The git log
command can be used to view the commit history for all branches. The syntax for the command is as follows:
git log [options]
The options
can be used to filter the output of the command, such as by date, author, or commit message.
To view the commits since branching off from another branch, you can use the ..
syntax. For example, if you have a branch called master
and a branch called feature
, and you want to see the commits that have been made on the feature
branch since it was branched off from the master
branch, you would run the following command:
git log feature..master
The output of the command will show the commit SHA-1, the author, the date, and the commit message for each commit that was made on the feature
branch but not on the master
branch.
Git Diff
The git diff
command can be used to compare the differences between the two branches. The syntax for the command is as follows:
git diff branchB...branchA
For example, if you have a branch called master
and a branch called feature
, and you want to see the differences between the feature
branch and the master
branch, you would run the following command:
git diff feature...master
The output of the command will show the differences between the two branches, one file at a time. The changes will be highlighted in color, so it is easy to see what has been added, removed, or changed.
The git diff branchB...branchA
command is a powerful way to see what changes have been made to a project between two branches. It can be used to track down bugs, to see how a feature was implemented, or to simply understand the history of a project.
To conclude, the git log
and git diff
commands are essential tools for working with Git branches. By understanding how to use these commands, you can easily inspect and compare the commits made in different branches, which can help you to track down bugs, implement features, and understand the history of your project.
In the next article, we'll discuss retrieving updates from another repository and updating local repos. If you have any queries, do write them in the comments below and follow me for more such content.
Subscribe to my newsletter
Read articles from Bhuvanesh Prasad directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by