Posts

Showing posts with the label Git

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...

Git - merge investigation commands

1. How to find out if branch has been merged into your current branch 2. How to find out if your current branch has been merged into any other branch 3. Edge case with cherry 🍒 (pick) 1. Check if a feature or branch has been merged into your current branch , use the git branch --merged command, the git merge-base command, or inspect the git log.  Methods to Verify a Merge: 1. Using git branch --merged  This command lists all branches whose tips are reachable from your current branch's HEAD, meaning they are fully integrated.  First, ensure you are on the branch where you expect the feature to be merged (e.g., main): git checkout <current-branch-name> Then, run the command to list all merged branches: git branch --merged If the feature branch name appears in the output list, it has been merged into your current branch.  To see branches that have not been merged, you can use the --no-merged flag instead:  git branch --no-merged 2. Using git merge-base This ...

Advanced work with git stash

Advanced work with git stash In Git, the most recent stash is  always  assigned the index  0 , appearing as  stash@{0} . When you create a new stash, all existing stashes are pushed down the stack (e.g., the previous  0  becomes  1 ).   1. Identify which stash is yours To see all your stashed entries and their assigned numbers, use: git stash list   This will output a list like this: stash@{0}: WIP on master: 4fd1101...  (Latest) stash@{1}: On develop: updated files...   2. View contents without applying You can inspect the contents of any stash entry using the  show  command. View a file summary (stat): git stash show stash@{0} (Shows only the list of files changed and the number of insertions/deletions) View full code changes (diff): git stash show -p stash@{0} (The  -p  or  --patch  flag shows the actual line-by-line code changes) View untracked files: git stash show --include-untracked stash@{0} Vie...