git version control tools Getting Started tutorial (using IDEA)

History
Linux open source projects use bitkeeper distributed version control system to manage and maintain the code, bitkeeper and Linux break up the partnership after, Linux team developed its own distributed version control system git.

The difference between git and svn:
①svn is a centralized management tool, you must connect to in order to submit the code on the server, modify, etc., if the single point of failure can not continue to work. ②git is distributed management tool, there is no central server, each person's computer is a complete repository.

git workflow

① clone resources from a remote repository to the local repository.
② from the local warehouse checkout code to the work area and then modify the code.
③ add the code before submitting the first from the work area to the staging area.
④ commit changes, commit from scratch to a local warehouse, local warehouse to save each modified version of history.
⑤ After modifications are complete, the team needs time and share code, the code can push to a remote repository.
Here Insert Picture Description

installation

Before installing over a long time does not work, open a command line, with the git clone https://github.com/git/gitupdated version of git it.
Here Insert Picture Description
After the update is completed by git --versionquery the current version
Here Insert Picture Description
also need to download a tortoisegit
Here Insert Picture Description
installation Note that this step is selected SSH
Here Insert Picture Description
Refresh after installing the language pack will have Chinese a
Here Insert Picture Description
directory on the election git bin directory of the
Here Insert Picture Description
user and mailbox just fill in on the line, the next step to determine the left option is SSH , then complete
Here Insert Picture Description


Local Warehouse

Create a local warehouse

You can create a new directory repository / repo1 the desktop, right-git bash here, use git init, then there will be a .gitdirectory (need to show hidden items)
Here Insert Picture Description

Adding to the local file repository

.git is the local repository .git directory contains repo1 is the working directory, add the file should be in the working directory, which is repo1 in.
Create a hello.txt, enter some random characters, add the following steps
Here Insert Picture Description
prompted the addition is complete click OK, click OK and the file is added to the staging area
Here Insert Picture Description
to documents submitted to the local warehouse from scratch, right click and choose submission
Here Insert Picture Description
must be Add the log information, and then submit
Here Insert Picture Description
Here Insert Picture Description
reboot you will find hello.txt submitted more than a green tick, very unhappy that other documents gave me marked with a question mark. .
Then the C: / Users / username /.git delete folders refresh it
Here Insert Picture Description
Here Insert Picture Description


Modify the contents of the file and submit a local warehouse

If you modify the contents of the file, it will turn red exclamation mark
Here Insert Picture Description
submitted again, add the corresponding log information
Here Insert Picture Description
submitted after a successful turn green
Here Insert Picture Description
you can see the changes by displaying the log information
Here Insert Picture Description
Here Insert Picture Description


Deleted files and restore local warehouse

Direct right to delete
Here Insert Picture Description
if you need to recover:
Here Insert Picture Description
Here Insert Picture Description
Here Insert Picture Description
Here Insert Picture Description
If you really want to delete, then delete once submitted after this time will not be restored completely removed
Here Insert Picture Description


Add the Java project to a local warehouse

To copy the Java project to the next local repository directory
Here Insert Picture Description
is added right to the staging area
Here Insert Picture Description
will be useless and out of .idea directory ignored
Here Insert Picture Description
choose to keep the local file, and then add .gitnore, and finally return to the previous directory submission
Here Insert Picture Description
successfully submitted
Here Insert Picture Description


Remote repository

Create a remote repository on github

Careful not to check initialization using readme
Here Insert Picture Description

Create and configure SSH public key on GitHub

By local repository ssh-keygen -t rsato create a key
Here Insert Picture Description
generally created in the user's directory .shh
Here Insert Picture Description
Notepad to open at the end .pub public key, the configuration settings in the GitHub
Here Insert Picture Description

The local repository through SSH pushed to the remote

Open the remote repository you just created, find the command to push the local repository
Here Insert Picture Description
using the command line in a local warehouse push
Here Insert Picture Description
refresh rediscovered exam project has been pushed to come
Here Insert Picture Description

Use tortoisegit

Create a new remote repository
Here Insert Picture Description
synchronization in the local repository git right-
Here Insert Picture Description
click the management
Here Insert Picture Description
first ssh client network settings git native of ssh.exe configure
Here Insert Picture Description
sets a remote url to a remote repository url, putty ssh key is a key before without the private key in ending the pub
Here Insert Picture Description
after determining, then click on the push
Here Insert Picture Description
refresh myRepo2 remote repository, it has been pushed to come
Here Insert Picture Description


Use https push

Then create a new repository
Here Insert Picture Description
using a local warehouse tortoisegit, configuring the remote, url https address for the remote repository directly copy the browser address bar on the list
Here Insert Picture Description
and click OK, select Yes, and then push
Here Insert Picture Description

Cloning a remote repository to local

Using SSH
Here Insert Picture Description
to copy the address, open a command line bash at a local warehouse, using the git clone 复制的地址conduct clone
Here Insert Picture Description
using HTTPS
Here Insert Picture Description
right git clone
Here Insert Picture Description
copy the address to https url bar
Here Insert Picture Description
cloning success
Here Insert Picture Description


Push / pull file modification

Here Insert Picture Description
Update.txt create a local repository, and then added to the staging area, added to the local repository, pushed to the remote repository
Here Insert Picture Description
Here Insert Picture Description
refresh remote repository, updated
Here Insert Picture Description


Local warehouse pull updated files
Here Insert Picture Description
selected in the git pull to sync in
Here Insert Picture Description


File conflicts

Now repo1 and myRepo in both update.txt files, modify them separately and submitted to the local repository
Here Insert Picture Description
Here Insert Picture Description
after repo1 submitted, and push to the remote repository, push success
Here Insert Picture Description
after modifications myRepo, the local and submit
Here Insert Picture Description
submit success
Here Insert Picture Description
when it pushed to a remote repository fail because remote repository update.txt repo1 has been modified, and now myRepo is not up to date, the CAS mechanism similar to Java. . repo1 and myRepo have taken to that update.txt, while modifying and found not to be updated when repo1 to be updated, direct update, found that has been updated when myRepo updated, so push failed. .
Here Insert Picture Description
You can not push, pull choose
Here Insert Picture Description
choice to solve the conflict
Here Insert Picture Description
open the file delete these three lines
Here Insert Picture Description
will be submitted to the local repository, and then push
Here Insert Picture Description
this time in a remote repository successfully updated
Here Insert Picture Description


Private remote repository

Creating a private git server on Linux

I am using centos8 virtual machine
to use yum install gitto download and install git
Here Insert Picture Description
After installation with git --versioninquiries installed version
adduser -r -c 'git version control' -d /home/git -m gitin / home / git to create a git user, and then change the git user's password
Here Insert Picture Description
to switch to git user cd into your home directory create a repo1 warehouse
Here Insert Picture Description
use git init --bareinitialization
Here Insert Picture Description

Pushed to the remote repository linux

In the windows of the local repository push the url following settings, 192.168.2.142 is my ip address of the virtual machine
(I did not even think I can connect the virtual machine is a bridge mode ip address I do not know how to find even one afternoon with secureCRT no success would have been ready to give up ... I do not know)
Here Insert Picture Description
the process to enter the user's password just git
Here Insert Picture Description

Cloned from a remote repository

Here Insert Picture Description
the same url and just
Here Insert Picture Description
let you enter the password git users after
Here Insert Picture Description
a successful replication of open warehouse
Here Insert Picture Description


Branch

Every time we submit, Git regard they strung together a timeline, this timeline is a branch. Up to now, only one timeline, in Git, this branch is called the main branch, that is, the master branch. HEAD pointer strictly speaking is not directed to submit, but point to the master, master is the point of submission, so HEAD is pointing to the current branch.

For example, Iron Man MK1 is the master, MK6 is a branch of a branch MK1, MK7 is the MK1, MK6 and MK7 are two branches of MK1, the development between them will not affect each other, similar to a binary tree. The combined branch is also possible, for example to fit MK6 and MK7 MK50, is master.

Creating a branch

Creating a branch warehouse Right repo1
Here Insert Picture Description
named branch
Here Insert Picture Description

Branch and merge conflict resolution

In the current (master) branch to create a master.txt, added to the staging area and submitted to the local repository
Here Insert Picture Description
Here Insert Picture Description
and then modify the contents of the update, and submit it to the master branch
Here Insert Picture Description
Here Insert Picture Description
Now switch to branch branch
Here Insert Picture Description
Here Insert Picture Description
can be found in branch branch is not master.txt file, update has not been modified, created branch.txt, and modify the contents of the update and submit
Here Insert Picture Description
Here Insert Picture Description
switch back to the master branch, merge
Here Insert Picture Description
merge branch selected branch
Here Insert Picture Description
more than a file created branch branch
Here Insert Picture Description
to open three sentences to remove this update
Here Insert Picture Description
to resolve the conflict
Here Insert Picture Description
submitted to the master
Here Insert Picture Description
success
Here Insert Picture Description


In operation git IDEA

Configure git

Create a new project gitTest
Here Insert Picture Description
search configuration settings in the git path test can be used to try and choose OK after configuring
Here Insert Picture Description
create a class in src, just write something
Here Insert Picture Description

Create a local warehouse

Create a local warehouse in the VCS in
Here Insert Picture Description
selecting the parent directory of the current project IdeaProjects, select ok
Here Insert Picture Description
after viewing the directory, you will find more of .git directory
Here Insert Picture Description

Adding to the staging area

Right idea to add the project back to the staging area
Here Insert Picture Description

Submit to the warehouse

Click on the top right corner of the green check mark to submit IDEA
Here Insert Picture Description
selection src and .imi configuration file, and then add comments, submit
Here Insert Picture Description
Here Insert Picture Description
the code before adding will be marked green
Here Insert Picture Description
Here Insert Picture Description

Pushed to the remote repository

From VCS-> git-> push
Here Insert Picture Description
clicks define remote, remote copy url githunb warehouse
Here Insert Picture Description
click push, will be asked to enter a GitHub account and password
Here Insert Picture Description
here I push failed, seemingly due to inconsistent versions reason, I re-create a warehouse
Here Insert Picture Description
in accordance with the prior step push to get this warehouse, a success -
Here Insert Picture Description
refresh the remote repository also find updated
Here Insert Picture Description

Cloned from a remote repository

Here Insert Picture Description
Copy githunb warehouse https url address to
Here Insert Picture Description
Here Insert Picture Description
all the way to choose yes and next, clone successfully
Here Insert Picture Description
add a line of code, submit, push
Here Insert Picture Description
open the github updated
Here Insert Picture Description

Pulled from a remote repository

Open the old code beginning
Here Insert Picture Description
click on the pull
Here Insert Picture Description
pull success
Here Insert Picture Description

Use branch

Create
Here Insert Picture Description
create a branch called dev
at this time of the current branch is dev, label on which branch, which is the current branch
Here Insert Picture Description
to add a method
Here Insert Picture Description
to submit
Here Insert Picture Description
click checkout back to the master
Here Insert Picture Description
at this time there are no methods dev
Here Insert Picture Description

Published 67 original articles · won praise 335 · views 50000 +

Guess you like

Origin blog.csdn.net/qq_41112238/article/details/105217415