Posts

Showing posts with the label commits

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 c ommand 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 Syntax Comparison Logic Best Used For git diff commit1 commit2 Compares the exact states of the two snapshots directly. Comparing arbitrary points in history. git diff commit1 .. commit2 Identical to using a space; compares the tips of both commits directly. Standard branch-to-branch...

How to list only commits which was made after branch was splitted(checkouted)

To list only the commits made on your current branch after it split from a parent branch, use the double-dot ( .. ) syntax with git log . 💻 The Best Commands Run this command from your current branch:  git log main..HEAD If you prefer a clean, single-line overview:   git log --oneline main..HEAD (Note: Replace main with master , develop , or whatever the name of your parent branch is.) 🔍 How It Works The .. operator acts as a set subtraction tool.  main..HEAD means: "Show me all commits reachable from HEAD (your current branch), but exclude any commits that are reachable from main ." This leaves you exactly with the new commits added to your feature branch since the day you used git checkout -b .   💡 Advanced Options Depending on your workflow, you can add flags to handle specific scenarios: Exclude Merge Commits: If you have pulled or merged other branches into your feature branch and only want to see your unique work, add --no-merges : git log main..HEAD...