Development/Tutorials/Git/Create a patch: Difference between revisions

From KDE TechBase
(First revision)
 
No edit summary
Line 1: Line 1:
{{warning|This page is yet to be reviewed for changes required by the migration to Git.  Information and commands on this page may no longer be valid and should be used with care. Please see the [[Development/Git|KDE Git hub page]] for more details. }}
This page is mostly useful for people who want to submit a patch against a git repository, but for any reason don't want to use merge requests.
This page is mostly useful for people who want to submit a patch against a git repository, but for any reason don't want to use merge requests.



Revision as of 14:08, 1 March 2011

Warning
This page is yet to be reviewed for changes required by the migration to Git. Information and commands on this page may no longer be valid and should be used with care. Please see the KDE Git hub page for more details.


This page is mostly useful for people who want to submit a patch against a git repository, but for any reason don't want to use merge requests.

Setting up git

You will need to set up git for your user if you still did not do it. It's quite easy and it boils down to these two commands:

git config --global user.name "Your name"
git config --global user.email "Your email address"

Then you're good to go, and all your commits will be signed with your name and email

Using git-format-patch to send patches through email

This method will let you create a patch (or a set of patches) ready to be applied. We will suppose we want to add a FooClass to Amarok (which obviously does not exist).

Starting off

First of all, you will have to clone the repository. Amarok repository lies here: http://gitorious.org/amarok/amarok . Let's start by cloning the repository. In a terminal you would write:

git clone git://gitorious.org/amarok/amarok.git

This will download the repository in a directory named "amarok" on your machine.

Getting the work done

We create the FooClass.{cpp,h} files and start modifying them. Once we're satisfied, we're ready to commit the result. Since we have created new files, we need to add them to the repository:

git add FooClass.{cpp,h}

Good to go. Now we can commit the result.

git commit -m "Adding important FooClass for Amarok"

You obviously should change the message to what suits you more. Now, let's suppose that right when you are about to send the patch you find out about a small mistake in the file. Don't panic, just do your modification, and commit again (no need for git add this time)

git commit -am "Updating FooClass"

Don't worry about the 2 commits: git will handle that for you

Creating the patch

Ok, so our work is done and we just need to create the patches. It's really simple; just do

git format-patch origin

This command will create a set of patches out of all the commits you made since you cloned the repository. When running this command, you should be prompted a list of created files, one per commit. They should be named like <number>-commit-message.patch; so in our case git format-patch would create 0001-Adding-important-FooClass-for-Amarok.patch and 0002-Updating-FooClass.patch. Remember to send ALL the patches, and not just the last ones!

These patches contains also your commit information, so your name will appear in the commit log.

Sending the patch

You can now send the patch to ReviewBoard, to a developer, or using git send-email. The latter method will not be covered here since it needs some additional configuration. Please see git help send-email to learn more about it.