How to compare 2 commits in git

How to compare 2 commits in git 

To compare two commits in Git, you use the git diff command followed by the commit identifiers. 

Compare via Command Line
  • Detailed code changes: Run git diff <commit1> <commit2> to see line-by-line differences between two commits.
  • High-level summary: Run git diff --stat <commit1> <commit2> to view a list of changed files and line counts.
  • Single file comparison: Run git diff <commit1> <commit2> -- <path/to/file> to restrict the comparison to one specific file. 
Note: You can use full commit hashes, short 7-character hashes, or reference pointers like HEAD and HEAD~1.
Understanding Comparison Types
Notation SyntaxComparison LogicBest Used For
git diff commit1 commit2Compares the exact states of the two snapshots directly.Comparing arbitrary points in history.
git diff commit1..commit2Identical to using a space; compares the tips of both commits directly.Standard branch-to-branch or commit comparisons.
git diff commit1...commit2Compares the common ancestor of both commits with commit2.Seeing only changes introduced by a feature branch, ignoring target updates.

Comments

Popular posts from this blog

30 маловідомих, але корисних команд Linux (repost)

15 поширених команд Linux (repost з ITEDU.center)