No copy code — eclipse uses git to submit the project – transfer
Original address: http://blog.csdn.net/u014079773/article/details/51595127
preparation:
Purpose: Eclipse uses git to submit local projects to remote GitHub
Eclipse version: Eclipse 4.0 5 64 bit
JDK version: jdk-1.7 64 bit
Project type: Maven web project
Note: the higher version of eclipse comes with the GIT plug-in, while the lower version needs to install the GIT plug-in. The higher version of eclipse is used here, and the lower version installs the GIT plug-in, which is not introduced here.
Eclipse uses git to submit projects in two ways: one is the GIT command window, and the other is the GIT plug-in provided by eclipse (same as SVN plug-in)
1、 Submit the project using the GIT command window
1. First download git from the official website and install it, and then configure the user information (right click "git bash here" in any directory to open the GIT command window)
git config --global user. name "you name"
git config --global user. email " you@youdomain.example.com "
2. Log in to GitHub official website, register personal GitHub account, and create SSH key to upload local projects to remote GitHub
Create SSH key: SSH keygen - t RSA - C“ youemail@example.com "
Copy the generated public key to GitHub. For specific operations, refer to "VI: add remote warehouse" in
3. Create a local warehouse, such as "testgit", then select the local warehouse and right-click "git bash here" to execute the following command: (note that the warehouse name is in English)
First, create a warehouse on GitHub with the name of "testgit" (the name of the remote warehouse must be consistent with the name of the local warehouse, otherwise the submission fails and the warehouse does not exist). For the specific operation of creating a remote warehouse, refer to:
"VI: add remote warehouse"
Right click "git bash here" on the "testgit" project and enter the following command:
Git init initializes the warehouse "testgit", that is, turn this directory into a warehouse that git can manage, and a hidden file ". Git" will be generated in this directory
touch . Gitignore git submission ignores unnecessary folders or files (generate a hidden file ". Gitignore" in the local warehouse, and open the text editor to set the files or folders to be ignored, such as the target folder of Maven project)
git add . Add all files (add and "." There are spaces between, otherwise unrecognized syntax, submit all files)
Git commit - A - M 'version 1.2' submit all modified files
git remote add origin git@github.com :somenone/testGit. Git submits to the remote warehouse (associate a remote warehouse in the form of SSH)
Git push - U origin master push remote warehouse
Note: since the remote library is empty, we added the - U parameter when pushing the master branch for the first time. Git will not only push the contents of the local master branch to the new remote master branch, but also associate the local master branch with the remote master branch. In future push or pull, we can simplify the command.
After that, the implementation is git push origin master
At this point, our local project has been submitted. Log in to the remote GitHub and find that the upload is successful.
2、 Submit the project using eclipse's own plug-ins
1. Configure our user name and password with git plug-in, that is, our own GitHub registered user. windows--perferences--Team--Git--Configuration
2. Eclipse generates SSH2 key: Windows -- permissions -- General -- network communication -- SSH2 -- Key Management -- General RSA key
Then register the generated SSH key on GitHub, log in to GitHub -- settings -- add, and paste the SSH key generated by the appeal.
Note: this method is equivalent to the command line method. You can paste the generated SSH key on the company computer and your own laptop, and you can add many SSH keys
Check whether the generated secret key is on the default system disk (Disk C). Some people will install it on other disks.
Then paste the generated public key to GitHub: (this step cannot be omitted. Be sure to use the command to check whether the generated public key is normal)
If there is no operation in this step, execute the command: $SSH - T git@github.com This error is reported:
3. Create projects locally, such as "testgit" and local git warehouse
Open eclipse, create a project "testgit", write anything in it, and then "file" -- "team" -- "share project" -- "git" -- "next"
As shown in the above figure, the project "testgit" becomes a git warehouse. Open the project in workspace and find an additional hidden file ". Git", but the project is in untracked status (indicated by the symbol "?" in the folder). Next, we need to submit the code to the local warehouse, as shown in the following figure:
First, we need to ignore unnecessary files, such as the Maven project target folder
to configure. Gitignore to exclude this folder, open the Navigator window and add it in the project root directory Gitignore file, write the directory that needs to be excluded from control In gitignore file:
In this way, GIT submission filters some unnecessary files. If you want to filter other folders or files, write them directly in ". Gitignore". For the specific writing method, refer to:
Then, the modified file must be added first and then committed, so the file can be added to the GIT index through team - > add to index for version monitoring:
If you do not want to add it to the version library, the command "remove from index" is provided that it is not committed. If it is committed, the command will not work. After the file is added successfully, the status of the file is changed by the previous "?" Become "*":
Details: as long as commit in egit, untracked files can be added to the index by default and then submitted for update. There is no need to operate separately
Finally, execute commit: (after the first commit, the master branch will be automatically generated)
Enter the submission information in the comment:
This project "testgit" was successfully submitted locally. Next, we submit the local project to the remote warehouse GitHub:
First, log in to the GitHub official website and create the warehouse "testgit" (the name is consistent with the local warehouse name, which means that the local warehouse is submitted to and associated with the remote warehouse). After creation, perform the following operations:
Make the following settings:
Select from the drop-down box as follows:
Then enter the following screenshot operation: Note: if "force update" is checked, it means to overwrite the submission
Click "next", as shown in the following figure:
Finally, click finish as shown in the figure below to log in to GitHub to check whether the upload is successful.
The following screenshot shows that the upload was successful.
Supplement:
1. How to submit a modified project? A "*" sign appears in the modified project folder. Select a file with a "*" sign and right-click "team" -- "commit"
Click "commit and push" to submit and push, that is, submit the modified file to the local and push it to the remote warehouse.
2. How to recover uncommitted modified files:
3. In the actual development, only the following three documents need to be submitted:
4. How to view and modify remote URL with command:
If you need to switch to the GIT protocol when connecting to the GitHub warehouse, you can use git remote - V to view your current remote URL
$ git remote -vorigin https://github.com/love-somnus/Spring.git (fetch)origin https://github.com/love-somnus/Spring.git (push)
You can see that it is accessed using HTTPS protocol.
At this time, you can use git remote set URL to adjust your URL.
git remote set-url origin git@github.com :love-somnus/Spring. git
After that, you can use git remote -v to check. OK now.
5. Check whether the local SSH key is normal:
$ ssh -T git@github.com # Attempts to ssh to github
The following message indicates that the setting is successful:
Hi username! You've successfully authenticated,but GitHub does not # provide shell access.
remarks:
1. When using Eclipse Plug-in to submit a project to a remote, you must first submit it locally and finally submit it to the remote warehouse
2. Check who submitted the code. Right click "team" -- "show history" of the project
3. View the submission record: Team -- show in history (command behavior: git log)
4. Undo recovery modification: replace with -- head revision (command line git checkout head.)
5. Update project remote warehouse: Team -- pull (command line: git pull) https://github.com/someone/xxx.git )
6. Check which files have been modified: Team -- synchronize workspace
7. When submitting the project, pay attention to ignoring unnecessary files or folders, such as the target folder under Maven project
8. Git provides multiple protocols to connect to the GIT server, among which HTTPS and git are the most common. Git can be free of user name and password. Different protocols and project connection addresses are different, as follows
HTTPS format: https://github.com/love-somnus/Spring.git Git form: git@github.com :love-somnus/Spring. git