Difference between revisions of "Git and EGit for Beginners"
(→Changing committer and author info)
|Line 58:||Line 58:|
== Mapping CVS Commands to Git ==
== Mapping CVS Commands to Git ==
Revision as of 15:18, 18 September 2012
First, understand that a "commit" in Git is no longer a remote operation. Git maintains a complete copy (clone) of the repository, so your commits no longer go on the server. Changesets are pushed to the server. You commit locally.
- If you're not using Eclipse Juno, now is a great time to upgrade
- Install EGit: Help > Install New Software, then Work with: choose Juno - http://download.eclipse.org/releases/juno
While you're there, install the PDT tools from Programming Languages.
Cloning Git repositories as new PHP projects
- Switch to the PHP Perspective (Window > Open Perspective > Other > PHP) then go to File > Import... Expand Git, and choose Projects from Git > Next
- This will allow you to create a new PHP project with the Git repo contents inside.
- Repository Source: URI > Next
- Don't enter the URI, but instead fill in the fields:
- Host: git.eclipse.org
- Repository Path: /gitroot/www.eclipse.org/(top-level-dir).git
- Protocol: SSH
- Port (leave blank; default)
- User: your committer ID (not your email address)
- Next, Next. Cloning may take a while -- don't forget, you're getting a complete clone of the repository.
- Use the New Project wizard (Finish), and choose a new PHP project from the Select a wizard dialog. Give it a name (I called mine "articles") > Next > Next > Finish
Repeat these steps for other web content you may need to connect to.
You'll end up with a new project, similar to the screenshot. The information between the square brackets is information about the Git repo.
Changing a file, committing, pushing
REMEMBER: a "commit" in Git is a LOCAL operation on your local Git clone. Committing does _nothing_ on the server -- that's what a PUSH is for!
In the screenshot below, you can see I changed the file "about.xml" since it has a change marker (>) in front of it.
- Right-click the file (or the parent folder, or the entire project) to commit the change(s) to your local repo. > Team > Commit
- Make sure all the correct files are checked, enter a commit message, and presss Commit. This is similar to CVS.
- PLEASE NOTE: The author and committer information must match that of your Eclipse Foundation committer record! See below for info on changing this.
- When the commit is complete, you'll notice the change markers are now gone. However, next to the repo, there is a marker to indicate that you have one outgoing change. Push it now: Right-click the repo > Team > Push to Upstream
- You'll also notice that the Team menu has a Pull option to pull changes in the remote repository. Always pull changes before editing files.
No one really cares what your name and email address are when you only commit locally. However, if you want your committed changes to be accepted by the Eclipse Git servers, the Committer information must match your committer record. To set them correctly in Eclipse:
- Window > Preferences
- type "git" in the search area
- Go to the Configuration item, press Add Entry and enter the information as depicted:
Be sure to provide values for both user.name (e.g. "Ian Skerrett") and user.email (e.g. "firstname.lastname@example.org").
Mapping CVS Commands to Git
A git PULL is the equivalent to a CVS Update. The difference is that you can only do a PULL at the project/repo level, unlike in CVS where you could update an individual file. Another difference is that there is not a master www project that you can update everything. Each sub-directory of eclipse.org is now a git repo, so you have to update each repo.
To do a PULL,
- select the project/repo
- right mouse click -> Team -> Pull
Editing a Page
You can make changes to any file the same way you do with CVS. You can save your changes locally in your workspace the same way as with CVS.
Committing a Change to the Eclipse.org server
In CVS, you needed to select a file or folder, and then under the Team menu select Commit to send the changes to the server
In git, it is a two step process. 1) You must COMMIT your changes at the file or folder level. This only commits them to a local git repository. To do the local commit, select the file, right-click menu, Team -> Commit. 2) To push them back to the server, you need to "Push to Upstream". You can only push to upstream at the project/repo level. You can't push an individual file, like you can in CVS.
To Push to Upstream, select the project/repo, select Team -> Push to Upstream.