6

I have a private Git repo that I cannot make public. I like to generate diff from my commits and ask outsider if my commits are good. To make him review my commit easy, I like color (red/green) to be applied to where my changes are. How can I save diff to a file?

leopoodle
  • 2,110
  • 7
  • 24
  • 36
  • 1
    `git diff > changes.diff` - if you use the `.diff` extention, some editors will give you the color highlighting - `.patch` may also work - depends on what you're using – Robbie Mar 08 '17 at 19:49
  • Possible duplicate of [Git Diff output to file preserve coloring](http://stackoverflow.com/questions/9706492/git-diff-output-to-file-preserve-coloring) – Robbie Mar 08 '17 at 19:54

2 Answers2

8

"git format-patch HEAD~" creates a diff for the last commit that you can send through email or as a file.

You can see more options on: https://git-scm.com/docs/git-format-patch

Markus Mauksch
  • 397
  • 1
  • 9
0

print the diff between previous and current version into a file:

git diff HEAD^ > /tmp/mypatch   

apply the changes to current working directory/branch:

git apply /tmp/mypatch      

create a "patch" file out of the diff between previous and current version:

git format-patch HEAD^    # creates a file like "0001-descriptiong-of-last-commit.path

print each patch to a seperate file, e.g. to send it per mail...

git format-patch master     

[a]pply [m]ailbox to git repo (e.g. git checkout -b myTestFromMailbox)

git am myPatchMailbox.mbox    

difference between git apply and git am

git apply - takes a patch (e.g. the output of git diff) and applies it to the working directory (or index, if --index or --cached is used).

git am - takes a mailbox of commits formatted as an email messages (e.g. the output of git format-patch) and applies them to the current branch. (git am uses git apply behind the scenes, but does more work before (reading a Maildir or mbox, and parsing email messages) and after (creating commits).)

MacMartin
  • 2,366
  • 1
  • 24
  • 27