Notice: This Wiki is now read only and edits are no longer possible. Please see: https://gitlab.eclipse.org/eclipsefdn/helpdesk/-/wikis/Wiki-shutdown-plan for the plan.
Difference between revisions of "CDO/Git"
(New page: = How to create a patch = EGit can only create patches describing a single commit. This is inadequate, because it's highly likely that you'll commit many times onto a local branch before...) |
|||
Line 33: | Line 33: | ||
#Run 'git diff' as follows: git diff origin/master HEAD (assuming that your dev branch is checked out, which makes HEAD reference it) | #Run 'git diff' as follows: git diff origin/master HEAD (assuming that your dev branch is checked out, which makes HEAD reference it) | ||
<br> | <br> | ||
− | = How to apply a patch = | + | = How to apply a patch = |
− | A patch created by 'git diff' is in the ''unified diff'' format, basically the same as the output format of 'diff -c' | + | A patch created by 'git diff' is in the ''unified diff'' format, basically the same as the output format of 'diff -c' |
− | on a *Nix platform. Eclipse cannot apply such a patch. You'll have to use a "real" patch processor, such | + | on a *Nix platform. Eclipse cannot apply such a patch. You'll have to use a "real" patch processor, such |
− | as | + | as Git itself, or GNU patch. |
− | |||
+ | With Git, apply the patch works as follows: | ||
+ | <pre>~/my/git/repo# git apply /path/to/mypatch.txt | ||
+ | </pre> | ||
− | |||
− | + | Or with GNU patch:<br> | |
<pre>~/my/git/repo# patch -p1 < /path/to/mypatch.txt | <pre>~/my/git/repo# patch -p1 < /path/to/mypatch.txt | ||
</pre> | </pre> | ||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
<br> | <br> | ||
− | + | <br> | |
− | + | ||
− | + | ||
<br> | <br> | ||
<br> | <br> |
Revision as of 06:21, 8 November 2011
How to create a patch
EGit can only create patches describing a single commit. This is inadequate, because it's highly
likely that you'll commit many times onto a local branch before you're ready to create a
single patch covering that series of changes.
Fortunately Git itself makes patch creation very easy. The most versatile format of its diff command is:
# git diff <commit1> <commit2> > mypatch.txt
This creates a patch 'mypatch.txt' describing the differences between commit1 and commit2.
(Remember that in Git a commit is a snapshot, not a changeset. Therefore, any two commits
can be compared.) There are other ways of using git diff, but this is the most generic way
of invoking it.
If you're creating a patch for review, then the patch should apply cleanly against origin/master.
This suggests the following workflow:
- Develop on a local development branch, committing as often as you like
- Merge origin/master into your development branch whenever you want, but at least once, right before you create your patch.
- Commit the merge, if it wasn't committed automatically. (Git's default behavior is to commit automatically if there are no conflicts.)
- Run 'git diff' as follows: git diff origin/master HEAD (assuming that your dev branch is checked out, which makes HEAD reference it)
How to apply a patch
A patch created by 'git diff' is in the unified diff format, basically the same as the output format of 'diff -c'
on a *Nix platform. Eclipse cannot apply such a patch. You'll have to use a "real" patch processor, such
as Git itself, or GNU patch.
With Git, apply the patch works as follows:
~/my/git/repo# git apply /path/to/mypatch.txt
Or with GNU patch:
~/my/git/repo# patch -p1 < /path/to/mypatch.txt