Search code examples
gitdiffgit-diff

Is it possible to 'git diff' 2 strings?


I have 2 strings and I want the git diff between them. I could create file1 and add string1 as its contents.

Then I could create file2 and add string2 as its contents. Then I could git diff file1 and file2.

However, given that I have the strings as strings (and not as file contents) can I avoid these long-winded steps? Is there an easier way?

Something like:

git diff "my first string" "my second string" # obviously does not work

Solution

  • If you insist on the git way,

    git diff $(echo "my first string" | git hash-object -w --stdin) $(echo "my second string" | git hash-object -w --stdin)  --word-diff