Http://www.cnblogs.com/yejiurui/archive/2013/07/29/3223153.html
http://blog.csdn.net/shehun1/article/details/9003039
To save to private
Git Introduction
Git is a free, distributed version Control tool, or a source code management tool that emphasizes fast. Each git working directory is a completely separate code base with complete history and version tracking capabilities, independent of the network and hub servers.
When you manage a project, Git has three working areas locally: Git's local data directory, working directory, and staging area. As shown in the following:
So there are only three states in Git for any file: committed (committed), modified (modified), and staged (staged).
Installation and Configuration Git
Terminal operation:
sudo apt-get install git git-core
First go to https://github.com/to register an account, of course, free and opensource users.
Create a git directory under the root directory.
mkdir ~/git
Initialize two parameters:
git config--global user.name = "username"
git config--global user.email = "***@*****"
Because this computer is linked to GitHub via SSH, the SSH key is created first.
Take a look at whether the computer already has an SSH key.
CD ~/.ssh
Prompt for no files or directories to indicate that the machine has not been created, continue to execute
Ssh-keygen-t rsa-c "[Email protected]"
All the way to enter, under the root directory will be produced. SSH folder (hide, view hidden folder then press ctrl+h), there is a production key file.
Open ~/.ssh/github.pub with gedit, copy the contents of the file to the Clipboard, (preferably with gedit, other tools may appear newline space)
Back to the GitHub page, click acount setting,
Point ssh keys,
Title take whatever you want, key inside the contents of the previously copied public key to stick in
Click Add.
Terminal test:
ssh-t [email protected]
The result of a successful connection is like this:
If it appears
Agent admitted failure to sign using the key.
Permission denied (PublicKey).
Perform
Ssh-add
There's no problem with connecting again.
Use git
One of the easiest ways to use it is to download other people's Open source projects from GitHub.
Open a page for an open source project
You can download the project directly by clicking on the ZIP package in the top left corner.
More convenient is to run the command at the terminal to download the source code.
Terminal operation:
git clone https://github.com/SimonVT/android-menudrawer.git
The entire project is automatically downloaded to the current directory.
The next thing to do is to share your project on GitHub and version control.
Start by creating a project on GitHub.
On the profile page, click New on the Responsitories tab
Fill in some information, click Create Respository
The project on GitHub is created.
Next, download the project and configuration file from the server to local.
Terminal operation:
mkdir ~/git/repos
CD ~/git/repos
git clone [email protected]:* **/***.git
Once executed, the project on GitHub is copied under the Repos folder.
Editing a project locally, such as adding a file,
You can update the project with the following command.
git Add. Add and modify files to the staging area without processing deleted files
git status//compare local Data directory and staging area changes
git commit-m "commit directions"//Refer to the code to the local data directory and add the commit instructions
It is possible that you and others to change the same file, then the conflict situation is unavoidable, then after the submission of the code, will prompt the code conflict files, we need to do is to deal with these conflicts, and resubmit:
Git pull//update code
Modify the code in the conflicting file as prompted
git Add.
git commit-m "Commit directions"
When you are done with the above steps, you need to synchronize the data from the repository of the local data directory to the GitHub server.
git push
After the submission is completed, refresh the GitHub page and find that the file has been updated.
in the Eclipse integrated in git
First install the Git plugin, in Eclispe,
Help->install New software.
Enter Address
Http://download.eclipse.org/egit/updates
Then the next step, the plugin is installed.
Create a project in Eclipse.
Then right-click the->team->share project->git->next on the project.
Select Use or create repository in parent folder of project, for example, point finish.
After execution completes, a. Git folder is created in the project folder and the repository is created.
Because there are some files in the project that are not necessarily uploaded, such as the Bin folder, it needs to be set up in the project.
Expand the corresponding project, there are small arrows to upload to the server directory, in the directory you do not want to upload right-click, Team->ignoe, the directory will be ignored.
Here's the commit code to this machine.
On the project, right-click Team->commit.
Select the file to commit, click Commit, and when finished, the code is uploaded to the local server.
Next, upload the code to GitHub's server.
In the command line, go to the project's folder, run
Git remote add Origin https://github.com/SilangQuan/LinearCompiler.git
Re-execute
Git push-f
After successful execution, it looks like this:
Check out the GitHub Project homepage and discover that the files have been uploaded.
After you have modified the project code in Eclipse, you can commit the code by right-clicking Team->push on the project after commit.
After uploading to GitHub, additional members of the team can extract the project through Eclipse->file->import->project from Git->uri.
In team development, it is common to fecth the latest code before the new day starts working.
Directly in the project want right click->team->fetch
Execute the->team->merge again.
The new files on the server will be added.
Reference: