added brief explanation of svngit2jira
clarified that adding a git reference to Jira happens automatically if using svngit2jira syntax
|Deletions are marked like this.||Additions are marked like this.|
|Line 135:||Line 135:|
|Note that the first line does two things: (1) it is less than 50 characters. Subsequent lines after the first may exceed 50 characters. (2) it references a Jira issue by its id (CB-1234). Commonly, there should be a Jira issue open for defects and new features, and it is good practice for commits to point to the Jira issue they are addressing. And vice versa, you should add a comment to the Jira issue referencing the commit id(s) that contain your work. By adding the Jira number in square brackets in the commit message, there will be an [[http://www.apache.org/dev/svngit2jira.html|automatic comment]] added to the Jira item with the commit id.||Note that the first line does two things: (1) it is less than 50 characters. Subsequent lines after the first may exceed 50 characters. (2) it references a Jira issue by its id (CB-1234). Commonly, there should be a Jira issue open for defects and new features, and it is good practice for commits to point to the Jira issue they are addressing. And vice versa, you should add a comment to the Jira issue referencing the commit id(s) that contain your work. By adding the Jira number in square brackets in the commit message, you can take care of both in one step: there will be an [[http://www.apache.org/dev/svngit2jira.html|automatic comment]] added to the Jira item with the commit id, and of course the Jira item id will be in the git commit message.|
Look at the Website
There is an intro to contributing here: http://cordova.apache.org/#contribute.
Contributor License Agreement
Fork the official Apache Cordova project mirror with git. Git is the chosen revision control system for the Cordova project. There are many places to clone the code from:
Committers will typically fork from the official Apache server, since they are authorized to commit directly back to it. This is the authoritative / official repo.
However, contributors should typically fork from GitHub. This makes it easy to submit pull requests, which is the preferred method to make contributions as a non-committer. So as a contributor you should:
Create an account on github.com. Note that your repositories will have a URL of the form 'https://github.com/you' where the string 'you' is your userid. For the exercise here, substitute 'you' with your github userid. The official github repos that are read-only are at https://github.com/apache.
Note that Cordova has each component in a separate git repository, so there are many git repositories that compromise the entire project. They all start with "cordova-". So for this exercise we will use the fake name "cordova-x", which you should replace with the specific repository(s) you want to work with, such as "cordova-docs" or "cordova-android". The full list is on the Cordova home page.
On the GitHub web interface, fork github.com/apache/cordova-x.git to your own account on GitHub (ie, github.com/you/cordova-x.git).
From your workstation, clone your GitHub repo (ie, github.com/you/cordova-x.git) to your workstation. For example, to clone a Cordova repository, from your workstation shell you would run (note the "https" protocol):
$ git clone https://github.com/you/cordova-x.gitYou should now have a "cordova-x" directory with the extracted source.
- Add a pointer back to the official repo:
$ cd cordova-x $ git remote add apache https://git-wip-us.apache.org/repos/asf/cordova-x.git
Here is a diagram of the repos and their flows:
If you want to simply check out the source code and don't plan on making contributions, then you can skip GitHub and clone directly from the Apache servers: $ git clone https://git-wip-us.apache.org/repos/asf/cordova-x.git
Working in git
The Cordova community encourages a certain type of workflow within git. However, the below are only guidelines.
A good habit to get into is using topic branches for your work, while keeping the master branch untouched. You can then keep the master branch up-to-date with the main repository without worrying about merge conflicts.
Reduce Merge Conflicts
By not working on the master branch, you ensure that the branch's history will not diverge from the main repository's master branch. This allows you to pull in updates from the main repository without merge conflicts.
Organize and Isolate Contributions
By creating a topic branch for each contribution, you effectively isolate your changes into a single branch of history. As long as the topic branch is up-to-date, your changes will merge cleanly into the main repository. If your contributions cannot be merged cleanly, the repository maintainer may have to reject your contribution until you update it.
Easier for the Maintainer
Maintainers like topic branches. It is easier to review the pull request and merge commits into the main repository.
Consider that you've decided to work on ticket # CB-1234 for the cordova-docs repository. You are charged with updating some documentation.
Update your master branch
We're assuming you have cloned the docs repository as per the example above, and have the docs repository set up as a "apache" remote, with your own fork as the "origin". Let's first make sure your fork is up-to-date.
$ git checkout master $ git pull apache master $ git push origin master
Create a topic branch
Let's create a new branch based off of master and call it "CB-1234".
$ git checkout master $ git checkout -b CB-1234 $ git branch master * CB-1234
You can name the topic branch anything, but it makes sense to name it after the ticket. This topic branch is now isolated and branched off the history of your master branch.
Make File Changes
Let's update the accelerometer documentation for the "watchPosition" function.
$ myeditor accelerometer/watchPosition.md $ git status modified: accelerometer/watchPostion.md
git status shows that you have modified one file.
Commit the File Changes
git add will stage the file changes. You can then commit the staged file(s) with git commit. This is always the process to make changes to a git repository: stage, then commit.
$ git add accelerometer/watchPosition.md $ git status $ git commit
About Commit Messages
You are highly encouraged to describe your git commit with enough detail for someone else to understand it. In doing so, your commit message can consist of multiple lines. However, it also is highly encouraged that the first line of your commit message not exceed 50 characters. This is because some of the tooling that sits on top of git (such as the httpd apps that let you browse the repo) assume that the first line is top-level summary that is 50 characters or less. Thus there will be highlighting and truncating of the commit message using these assumptions, and it will look weird if these assumptions are not kept. And there should be a blank line between the summary and any further detailed body. For example, here is a good example of a commit message:
[CB-1234] Fixed the whizbang widget - added more sanity checking in the build script. - fixed the API to return the correct value in the scenario where there aren't any whizbangs present. - corrected the documentation. As an alternate to a bullet list, you could put long text here in paragraph form, with each line wrapped at 72 chars and blank lines between paragraphs.
Note that the first line does two things: (1) it is less than 50 characters. Subsequent lines after the first may exceed 50 characters. (2) it references a Jira issue by its id (CB-1234). Commonly, there should be a Jira issue open for defects and new features, and it is good practice for commits to point to the Jira issue they are addressing. And vice versa, you should add a comment to the Jira issue referencing the commit id(s) that contain your work. By adding the Jira number in square brackets in the commit message, you can take care of both in one step: there will be an automatic comment added to the Jira item with the commit id, and of course the Jira item id will be in the git commit message.
Long commit messages are not necessary, especially if there is a reference to a Jira item. More good advice on this topic is in the Git book.
Commit More File Changes
$ myeditor accelerometer/watchPosition.md $ git commit -a
Prepare to Send Pull Request
Before sending the pull request, you should ensure that your changes merge cleanly with the main documentation repository, and that the granularity of your commits make sense.
$ git checkout master $ git pull apache master $ git checkout CB-1234 $ git rebase master -i
The rebase -i step allows you to re-order or combine commits. This can help to make your commits more readable.
You can do this by pulling the latest changes from the main repository back into our master. We make sure that our master is always in sync before issuing pull requests. Next, we rebase the history of the master branch onto the topic branch ticket_11. Essentially, this will rewind your divergent commits, fast-forward your topic branch to the latest commit of the master, and then re-apply your topic branch commits in order. Ensures a clean application of code changes. The git community book has an excellent chapter on rebasing.
Alternatively, you can use git merge master instead of git rebase master, but your topic branches history may not be as clean.
Last thing is to make your code changes available from your fork.
$ git checkout CB-1234 $ git push origin CB-1234
Sharing your Changes
By pushing your topic branch onto your fork, an cordova-docs maintainer can review and merge the topic branch into the main repository.
Sending a Pull Request from GitHub
Pull requests sent to the Apache GitHub repositories are used to take contributions.
Open a web browser to your GitHub account's cordova-docs fork.
- Select your topic branch so that the pull request references the topic branch.
- Click the Pull Request button.
It is strongly recommended that you sign up for the mailing list before issuing a pull request. If your pull request is related to an existing JIRA issue, then add a comment to the issue with a link to your pull request. If it's not (or you're feeling too lazy to search through JIRA), then you should email the mailing-list to notify committers of your pull request.
While Waiting, Continuing Crafting Commits
Since you worked on the topic branch instead of the master branch, you can continue working while waiting for the pull request to go through.
Be sure to create the topic branch from master.
$ git checkout master $ git pull apache master $ git checkout -b fix_ugly_vibrate_example $ git branch -a * fix_ugly_vibrate_example master CB-1234
When Your Pull Request is Accepted
$ git checkout master $ git pull apache master $ git log | more hey there's me! ya!
You can now delete your topic branch, because it is now merged into the main repository and in the master branch.
PLEASE delete your topic branch on github origin, as that will automatically close your pull request. Alternatively, from the github web interface you can close your pull request while leaving your topic branch present. The goal here is for pull requests to be closed after they are merged, so we don't end up with a bunch of pull requests that appear unresolved.
$ git branch -d CB-1234 $ git push origin :CB-1234
I know, deleting a remote topic branch is ugly (git push origin :CB-1234).
If Your Pull Request is Rejected
In this case, you just need to update your branch from the main repository and then address the rejection reason.
$ git checkout master $ git pull apache master $ git checkout CB-1234 $ git rebase master ( edit, commit, edit, commit, etc...) $ git push origin CB-1234
Then delete your topic branch (or close your pull request) as described above.