Eclipse uses Git and github to learn notes

Source: Internet
Author: User

Project Hosting

1. First you need to build a remote repository on GitHub

When you click Create Repository, the appropriate Git repository will be created on GitHub and the following interface will appear:

Copy the HTTPS or SSH warehouse address, the remote warehouse operation is over.

2.eclipse Create the project. Then right-–>team–>share project on the item, the following interface will open:

This interface requires us to configure the project's local git repository, either using the current project's directory as the Git repository for the project, or by customizing the directories in other locations as a git repository. It should be noted that if you customize the other location as a git repository, then the project is hosted in its defined location, and the project is not in the same workspace as it was originally located. Here I use the project root directory under the project's workspace as the Git repository, so I need to tick the using or create repository in parent folder of project. The following interface will appear:

Tick the item and click the Create Repository button to create a new. Git folder and complete the configuration of the Git repository.

When you view the item, you can see the following display:

Here we need to first talk about the concept of head, which can be understood as a cursor or an index. It can record the relevant version information of the file operation, we can switch to the version we want to get based on the head information. You can refer to the git reset command used in the previous article.
This shows no-head that the project's files are not yet added to Git's version management, so we need to right-–>team–>commit again, commit the files under the project, commit them to the local git repository, as shown in:

Fill in the comments, select the file you want to submit, click Commit and Push, and the file will be submitted to the local repository and pushed to the remote repository. The following interface will appear:

This requires a copy of the address we had previously copied from GitHub, paste it at the URI, and then go down the road until finish. The interface that is pushed to the remote repository is then shown below:

Wait for the progress bar to go to the end, which completes the push operation to the remote repository.
Looking at the project at this point, you can see that it is no longer a no-head, but on the master Master branch, indicating that it has been associated with the main branch.

Go to our new repository on GitHub and you'll see the files that have been successfully managed.

New file

Add the Hellogit Java file to the SRC directory, and you will see a question mark on the file name and its upper directory, which indicates that the file was not added to the Git repository. We can add it to git local and remote repositories as follows. Right-–>team–>synchronize workspace will open the synchronized Operation view as follows:

Then, just like the one mentioned above, right-click –>commit–> Fill in the comment –>commit and push so that the new file is committed to the local and remote git repositories.

Develop in a personal branch

Usually we need to create a new personal branch from the master branch, then develop it on the personal branch, and finally merge the changes from the personal branch onto the master branch. So we can create a new personal branch and pull it up locally for development use by doing the following.
Create a new personal branch on GitHub, as follows:

Opening eclipse, right-–>team–>pull, will display the following interface:

Click OK to synchronize the remote-created Earl's personal branch to local.

At this point we need to switch to a personal branch for development. Right-click –>team–>switch To–>other, the following interface appears:

Click Checkout, click Checkout as New local branch in the next screen, and then finish. When this sequence of operations is complete, we switch to our personal branch and see that the branch behind the project name is no longer master, but Earl.

Branch Merge

When we have finished writing the code under our own branch, we need to submit it to the master branch after the test has been verified correctly. Generally, instead of submitting master directly, we commit to the remote personal branch and then merge this branch with Master. Let's take a look at how to merge the Personal branch with the master branch.
1. In the project, create a new system configuration file System.config.properties, add the database connection information to it, and then submit it to the remote personal branch.
2. Open the remote repository on GitHub, select the personal branch that submitted the System.config.properties file, and click the new Pull Request button to enter the following screen
You can see in this interface which files are involved in this submission's merge request, and what changes have been made to those files. Fill in the description of this merge request, click the Create Pullrequest button, the following interface appears:

After confirming, click the Merge Pull Request button, fill in the description, then click the Confirm Merge button to complete the merge operation.
When you switch to the Master branch, you can see that the profile has been merged into it.

Resolution of conflicts

In the actual development process, often encounter multiple people to modify the same file, if more than one person to the same file content modification and want to merge it into Master, there will be conflicting situations, if you need to add the modified content to master, then you need to resolve the conflict before merging. Let's take a look at how to resolve the conflict situation.
1. Simulate situations where multiple people modify the same file. Create a new branch in the remote repository and pull it locally.
2. Modify the System.config.properties file involved in the branch merge on the local branch, save and commit to the remote branch.
3. Select the branch on the remote GitHub repository and click on the new Pull request button and the following interface appears: You can see that the branch is currently not automatically merged with the master branch because there are conflicts between the two branches and the conflict needs to be resolved before merging can take place. After filling out the description, click the Create Pull Request button, which will open the following screen to resolve the conflict of branch see file, you can use the Web Editor or command line to resolve the conflict, here we use the Web editor to modify.
4. Click the Resolve Conflicts button to open the edit page as follows:
After we make the changes, click the mark as Resolve button, mark the conflict file as merged, then click the Commit Changes button to submit the file. You can see the operations page of the normal merge branch as soon as you commit, and then you can complete the branch-to-master merge by following the branch merge operation.

Postscript

Eclipse has basically integrated most of the GIT command line operations, and mastering Eclipse's operations on Git can also improve productivity for kids who are unfamiliar with command-line operations. Whether a white cat or a black cat, catching a mouse is a good cat. Versioning is a good tool regardless of command line or GUI. Eclipse has a lot to do with git, and I'll keep updating my Learning summary.

Eclipse uses Git and github to learn notes

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.