可以'git diff'2个字符串吗? [英] Is it possible to 'git diff' 2 strings?
本文介绍了可以'git diff'2个字符串吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有2个字符串,我想要它们之间的git diff。我可以创建file1并添加string1作为其内容。
I have 2 strings and I want the git diff between them. I could create file1 and add string1 as its contents.
然后我可以创建file2并添加string2作为其内容。然后,我可以git diff file1和file2。
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?
类似这样的东西
git diff "my first string" "my second string" # obviously does not work
推荐答案
如果您坚持使用git方式,
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
这篇关于可以'git diff'2个字符串吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文