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
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
You don't have to use git diff for that, Git is used to track the changes in your code base.
There is a good linux command for that
diff <(echo "my first string" ) <(echo "my second string")
This is a good answer https://stackoverflow.com/a/454549/4620609
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With