Use Git to submit a project without copy code--eclipse-Go

Source: Internet
Author: User



Original address: http://blog.csdn.net/u014079773/article/details/51595127



Preparatory work:



Purpose: Eclipse uses git to submit a local project to a remote github



Eclipse version: eclipse4.5 64-bit



JDK version: jdk-1.7 64-bit



Project type: MAVEN Web project



Note: The eclipse version comes with a git plugin, and the lower version installs the Git plugin itself, which is not covered here using the Eclipse High version and the low version of the Git plugin.



There are 2 ways that Eclipse uses Git to submit a project: One is a git command window, and the other is Eclipse's own git plugin (used as an SVN plugin)



First, using the GIT command window to submit the project



1. First download git and install it, 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 "[Email protected]"



2. Login to github website, register your github account, create ssh Key to upload your local project to remote GitHub



Create SSH key:ssh-keygen-t rsa-c "[Email protected]"



Copy the generated public key to GitHub, and refer to the following: http://blog.csdn.net/u014079773/article/details/49555989 "Six: Adding a remote repository"



3. Create a local warehouse such as "Testgit" and select the local warehouse right-click on "Git Bash here" to execute the following command:(note the warehouse name in English)



First create a warehouse on GitHub, the warehouse name is "Testgit" (the remote warehouse name must be the same as the local warehouse name, otherwise the submission fails, the report warehouse does not exist), create a remote warehouse specific operation reference:



http://blog.csdn.net/u014079773/article/details/49555989 "Six: Adding remote repositories"



On the "Testgit" project, right-click on "Git bash here" and enter the following command:



Git init initializes the repository "Testgit" to turn this directory into a repository that git can manage, where a hidden file ". Git" is generated.



Touch. Gitignore git commit ignores unnecessary folders or files (generates a hidden file in the local repository ". Gitignore", text editor opens settings to ignore files or folders such as MAVEN project's target folder)



git Add. Add all files (add with ".") There are spaces between, otherwise unrecognized syntax, commit all files)



Git commit-a-m ' version 1.2 ' commits all modified files



git remote add origin [email protected]:somenone/testgit.git submit Remote repository (in the form of SSH, associate a remote repository)



Git push-u origin master push remote repository



Note: Since the remote library is empty, the first time we pushmastera branch, with-uparameters, Git will not onlymasterpush the local branch content of the remote newmasterbranch, but also the local branch and themasterRemotemasterBranch Association. You can simplify the command at a later push or pull.



Then execution is GIT push Origin master



To this our local project has been submitted completed, log on to remote GitHub to see the upload success.






Second. submitting a project using Eclipse's own plugin



1. Bring your own Git plugin to configure our user name and password, which is our own GitHub registered user. Windows--perferences--team--git--configuration






2.eclipse generated SSH2 key:windows--perferences--general--network commection--ssh2--key management--general RSA key






Then register the generated SSH key on GitHub and log in to Github--settings--add to paste the SSH key generated by the appeal.



Note: This method is equivalent to the command line method, the company computer and its own laptop to paste the generated SSH key, you can add a lot of SSH key



See if the generated key is in the default system disk (C-drive), and some people will install it on other disks.






Then paste the generated public key onto GitHub:(This step cannot be omitted, be sure to check the generated public key with the command)






If the step is not operational, execute the command: $ ssh-t [email protected] Report such an error:






3. Locally created projects such as "Testgit" and local git repositories



Open Eclipse, create project "Testgit" and write something, then "File"-"Team"-"Share Project"-"Git"-"Next"


















As shown in this project "Testgit" will become a git repository, to open the project under workspace, found a hidden file ". Git", but the project is in the untracked state (the symbol in the folder "?" ), we need to submit the code to the local repository, such as:



First we have to ignore unnecessary files such as the MAVEN Project target folder






Configure the. Gitignore to exclude this folder, open the Navigator window, add the. gitignore file to the project root directory, and write the directory to which you want to exclude control to the. gitignore file:






This way, git commits to filter out some unnecessary files, if you want to filter other folders or files directly in the ". Gitignore" Write, the specific wording of the reference:



http://blog.csdn.net/u014079773/article/details/51602344



Then submit the modified file must first add and then commit through the team, add to index can add files to the GIT index for version monitoring:






If you do not want to add to the repository, the "Remove from Index" command is not a commit, and the command does not work if it is already a commit. The file status changes after the add succeeds by the previous "? "Into" * ":



Details: In Egit, you can add untracked files to the index and submit updates by default, without the need for separate operations






Last commit: (The Master branch is automatically generated after the first commit)






Enter the submission information in the comment:






To this project "Testgit" on the local submission success. Next we submit the local project to the remote remote repository on GitHub:



First, log on to the GitHub website and create the warehouse "Testgit" (the name is the same as the local warehouse name, which indicates that the local warehouse is submitted to and associated with the remote warehouse), and when created, do the following:






Make the following settings:






The drop-down box is selected as follows:






Then proceed as follows: Note: If "Force Update" is checked, it means overwrite the commit






Click "Next" to appear as shown:






Finally click Finis, log on to GitHub to see if the upload was successful.






The following appears to indicate the success of the upload.









Add:



1. How to submit the modified item, the modified project folder appears "*" sign, select the file with "*" Sign right click "Team"--"commit"






Click "Commit and push" to commit and push, i.e. commit the modified file to local and push to the remote repository.



2. How to recover an uncommitted modification file:






3. The actual development of the submission of the project only need to submit the following three files:






4. How to use the command to view, modify the remote URL:



If you are using the HTTPS protocol address when connecting to the GitHub repository, you also need to switch to the GIT protocol
You can use Git remote-v to view your current remote URL



$ git remote-v
Origin 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 the HTTPS protocol.



At this point, you can use Git remote Set-url to adjust your URL.



git remote set-url origin [email protected]:love-somnus/spring.git



When you're done, you can use Git remote-v to see it again. This is OK.



5. Check if the local SSH key is OK:



$ ssh-t [email protected]
# attempts to ssh to GitHub



The following information appears to indicate that the setting was successful:



Hi username! You ' ve successfully authenticated, but GitHub does not # provide shell access.





Note:



1. Submit the project using the Eclipse plugin to the remote must be committed locally, and finally committed to the remote repository



2. See who submitted the code, right-click on "Team"-"Show History"



3. View commit record: Team--show in history (command behavior: git log)



4. Undo recovery changes: Replace with--head Revision (command behavior git checkout HEAD.)



5. Update Project remote repository: team--Pull (command line: Git pull https://github.com/someone/xxx.git)



6. See which files have been modified: Team--synchronize Workspace



7. When submitting a project, be careful to ignore unnecessary files or folders such as the target folder under the MAVEN project.



8.git provides multiple protocols to connect to a git server, the most common is that HTTPS and Git,git is a user name and password can be free, different protocols, project connection address is a difference, as follows



HTTPS form: https://github.com/love-somnus/Spring.git git form: [Email protected]:love-somnus/spring.git



Use Git to submit a project without copy code--eclipse-Go


Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.