Reputation: 133
Any tool/technique/method for creating a new file from "git diff file1 file2" comment, so that the new file will only have the output of difference.
git diff file1 file2
Upvotes: 2
Views: 1307
Reputation: 523
In general, git is NOT used to get the differences between 2 files.
For that, you shall just use the diff
command. And for the case you want, use >
to send to output to a file, like:
diff file1 file2 >output_file
The git diff
is used to get the differences between 2 git references (commits/branches/tags/...).
Sending the output to a file is actually a patch, which can then be applied to another file. This patch may contains the differences of more than 1 file.
If you want to restrict the differences of 1 file between 2 git references, then you would do:
git diff ref1..ref2 file >diffs_of_my_file_between_ref1_and_ref2.patch
This patch can again be used against 1 file to reproduce the changes. With git apply
or simply the (non-git) patch
. That is another story.
Beware: there are different diff formats. It is possible to specify this format with the options.
Upvotes: 0
Reputation: 1214
If you want to store the output of git diff file1 file2
to another file, then you can achieve the same using the command git diff file1 file2 > output_file
.
If you have some data in the output file and you want to append the new difference then you can use the command git diff file1 file2 >> output_file
. This command will append the output of the git diff file1 file2
command to the output_file file.
Upvotes: 3