Git, Patches and new Contributors

I have recently committed in the Eclipse BPEL Designer some patches that were contributed in our Bugzilla. This fact itself is not important. However, I used the Git command apply and kept the author name in the commit. I had never used this feature before, but it is extremely powerful. And very convenient to track activities and propose new committers on a project.

I let some traces in this article (as an example and for me, for later).
Notice that the apply command did not work with EGit, I had to use the command line. I guess it will be fixed in a future version.

  • First, we need a patch, given as a diff file, e.g. in a bug entry.
  • As a committer, you should apply and check this patch. So, you first need to copy the patch in your (cloned) Git repository.
  • Get some stats about the patch :
    git apply --stat myPatchFile
  • Make sure the patch can be applied :
    git apply --check myPatchFile
  • Apply the patch :
    git apply myPatchFile
  • Delete the patch file.

Then, you can check that the patch works and then commit it, before pushing the modification.
One important thing is to keep the author’s name in the commit. The author and the committer are different. And both can be kept in the commit and in the history. Here is an example in the command line:

git commit -a --author="authorUsername <>"

After the push, both the author and commiter names will appear in the repository.

The author and committer names appear in the history

I don’t know if everyone in Eclipse projects uses this feature, but from the community perspective, this is very interesting (IMO).

4 thoughts on “Git, Patches and new Contributors

  1. Even better: use git format-patch and git am. Git format-patch will create a separate patch file for each commit by the contributor and preserve all of their author, date, commit message, etc. Each filename will begin with a number (0001-commit-subject-for-first-commit.patch, 0002-commit-subject-for-second-commit.patch, …). Example usage: “git format-patch -M origin/master” (or use the appropriate upstream in place of origin/master).

    Then, once you have the patches all you have to do is: git am 0001-… 0002-…

    A nice feature of Git, of course, is that you’ll be listed as the committer while the original author is preserved.

  2. By the way, just a note on your example:

    git commit -a –author=”authorUsername ”

    You should really be following the Git standard of using real names here, e.g.:

    –author=”John Doe “

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s