Trying to understand `git diff` and `git mv` rename detection mechanism

Git’s “similarity index” computation is not, as far as I know, documented anywhere other than in the source, starting with diffcore-delta.c. To compute the similarity index for two files S (source) and D (destination), Git: reads both files computes a hash table of all of the chunks of file S computes a second hash table … Read more

How do I see the differences between two branches?

Use git diff. git diff [<options>] <commit>..​<commit> [–] [<path>…​] <commit> is a branch name, a commit hash, or a shorthand symbolic reference. Examples: git diff abc123..def567, git diff HEAD..origin/master. That will produce the diff between the tips of the two branches. If you’d prefer to find the diff from their common ancestor to test, you … Read more

Export only modified and added files with folder structure in Git

git diff-tree -r –no-commit-id –name-only –diff-filter=ACMRT $commit_id git diff-tree -r $commit_id: Take a diff of the given commit to its parent(s) (including all subdirectories, not just the top directory). –no-commit-id –name-only: Do not output the commit SHA1. Output only the names of the affected files instead of a full diff. –diff-filter=ACMRT: Only show files added, … Read more

How to compare files from two different branches

git diff can show you the difference between two commits: git diff mybranch master — myfile.cs Or, equivalently: git diff mybranch..master — myfile.cs Note you must specify the relative path to the file. So if the file were in the src directory, you’d say src/myfile.cs instead of myfile.cs. Using the latter syntax, if either side … Read more

‘git diff’ doesn’t show enough

The important thing to realize about git diff A B is that it only ever shows you the difference between the states of the tree between exactly two points in the commit graph – it doesn’t care about the history. The .. and … notations used for git diff have the following meanings: So when … Read more