Difference between revisions of "Development/Tutorials/Git/Create a patch"

Jump to: navigation, search
 
(3 intermediate revisions by 2 users not shown)
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.
  
 
== Setting up git ==
 
== Setting up git ==
 +
 +
You can skip this part if your git is already set up correctly with your name and email address.
 +
 
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:
 
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:
  

Latest revision as of 20:44, 24 March 2012

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.

Contents

[edit] Setting up git

You can skip this part if your git is already set up correctly with your name and email address.

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

[edit] 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).

[edit] 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.

[edit] 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

[edit] 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.

[edit] 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.


This page was last modified on 24 March 2012, at 20:44. This page has been accessed 4,009 times. Content is available under Creative Commons License SA 3.0 as well as the GNU Free Documentation License 1.2.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V.Legal