Saving the entire git diff between two commits in a text file

GitDiff

Git Problem Overview


is there a way where I could save the entire difference between two diff in a text file?

Suppose I wanted all the changes between A1 and A10 on master branch.

--A11-A10-A9-A8-A7-A6-A5-A4-A3-A2-A1-master

Or, is there a way where I could get the entire diff in Terminal which I could copy+paste?

Git Solutions


Solution 1 - Git

Sure:

git diff A10..A1 > my.diff

Solution 2 - Git

git diff {commit1} {commit2} > diff.txt

Being {commit1} and {commit2} a reference to the initial and finish commits you want to compare (reference could be an entire or partial SHA, a tag, HEAD.....)

Solution 3 - Git

From man page..

git format-patch -k --stdout R1..R2

Solution 4 - Git

If you just need save diff between two recent commits, you can use this command as well:

git diff HEAD^ HEAD > diff.txt

Solution 5 - Git

to get all folder/filenames as output from diff use

git diff <commit1> <commit2> --name-only

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionPalak AroraView Question on Stackoverflow
Solution 1 - GitBrian CampbellView Answer on Stackoverflow
Solution 2 - GitLolitoView Answer on Stackoverflow
Solution 3 - GitforvaidyaView Answer on Stackoverflow
Solution 4 - GitAleks DorohovichView Answer on Stackoverflow
Solution 5 - GitbigideaView Answer on Stackoverflow