Reputation: 8960
Is it possible to compute the diff between a versioned file (at a specific SHA) and its possibly future content, stored as a string?
For instance, something like:
$ git diff -- file.txt@SHA "Future\ncontent\nof\nfile.txt"
Upvotes: 3
Views: 56
Reputation: 94726
You can compare versioned file(s) from different versions using git diff
:
git diff SHA -- file.txt
Or you can compare unversioned files using diff
or git diff --no-index
:
git diff --no-index file1.txt file2.txt
And you can compare an unversioned file with a string using <()
bashism:
diff file.txt <(echo -e "Future\ncontent\nof\nfile.txt")
But not both. That is, you cannot diff a versioned file with a string, but can extract the versioned file the same way:
diff <(git cat-file -p $SHA:file.txt) <(echo -e "Future\ncontent\nof\nfile.txt")
Upvotes: 2