How do you compare two commits in Git?

How do you compare two commits in Git?

a) git diff commit1 commit2
b) git compare commit1 commit2
c) git log commit1 commit2
d) git show commit1 commit2

Answer:

a) git diff commit1 commit2

Explanation:

The git diff commit1 commit2 command compares the differences between two commits. It shows the changes made in each commit, helping you understand what has been modified between two points in the project’s history.

For example, git diff abc123 def456 compares the changes between the commits with hashes abc123 and def456.

Understanding how to compare commits is essential for reviewing code, debugging, and tracking the evolution of your project.

Reference:

Top 100 Git and GitHub MCQ Questions and Answers

Scroll to Top