Reputation: 2482
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?
Upvotes: 7
Views: 10843
Reputation: 2866
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).)
Upvotes: 1
Reputation: 397
"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
Upvotes: 8