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.
installation
Before installing over a long time does not work, open a command line, with the git clone https://github.com/git/git
updated version of git it.
After the update is completed by git --version
query the current version
also need to download a tortoisegit
installation Note that this step is selected SSH
Refresh after installing the language pack will have Chinese a
directory on the election git bin directory of the
user and mailbox just fill in on the line, the next step to determine the left option is SSH , then complete
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 .git
directory (need to show hidden items)
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
prompted the addition is complete click OK, click OK and the file is added to the staging area
to documents submitted to the local warehouse from scratch, right click and choose submission
must be Add the log information, and then submit
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
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
submitted again, add the corresponding log information
submitted after a successful turn green
you can see the changes by displaying the log information
Deleted files and restore local warehouse
Direct right to delete
if you need to recover:
If you really want to delete, then delete once submitted after this time will not be restored completely removed
Add the Java project to a local warehouse
To copy the Java project to the next local repository directory
is added right to the staging area
will be useless and out of .idea directory ignored
choose to keep the local file, and then add .gitnore, and finally return to the previous directory submission
successfully submitted
Remote repository
Create a remote repository on github
Careful not to check initialization using readme
Create and configure SSH public key on GitHub
By local repository ssh-keygen -t rsa
to create a key
generally created in the user's directory .shh
Notepad to open at the end .pub public key, the configuration settings in the GitHub
The local repository through SSH pushed to the remote
Open the remote repository you just created, find the command to push the local repository
using the command line in a local warehouse push
refresh rediscovered exam project has been pushed to come
Use tortoisegit
Create a new remote repository
synchronization in the local repository git right-
click the management
first ssh client network settings git native of ssh.exe configure
sets a remote url to a remote repository url, putty ssh key is a key before without the private key in ending the pub
after determining, then click on the push
refresh myRepo2 remote repository, it has been pushed to come
Use https push
Then create a new repository
using a local warehouse tortoisegit, configuring the remote, url https address for the remote repository directly copy the browser address bar on the list
and click OK, select Yes, and then push
Cloning a remote repository to local
Using SSH
to copy the address, open a command line bash at a local warehouse, using the git clone 复制的地址
conduct clone
using HTTPS
right git clone
copy the address to https url bar
cloning success
Push / pull file modification
Update.txt create a local repository, and then added to the staging area, added to the local repository, pushed to the remote repository
refresh remote repository, updated
Local warehouse pull updated files
selected in the git pull to sync in
File conflicts
Now repo1 and myRepo in both update.txt files, modify them separately and submitted to the local repository
after repo1 submitted, and push to the remote repository, push success
after modifications myRepo, the local and submit
submit success
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. .
You can not push, pull choose
choice to solve the conflict
open the file delete these three lines
will be submitted to the local repository, and then push
this time in a remote repository successfully updated
Private remote repository
Creating a private git server on Linux
I am using centos8 virtual machine
to use yum install git
to download and install git
After installation with git --version
inquiries installed version
adduser -r -c 'git version control' -d /home/git -m git
in / home / git to create a git user, and then change the git user's password
to switch to git user cd into your home directory create a repo1 warehouse
use git init --bare
initialization
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)
the process to enter the user's password just git
Cloned from a remote repository
the same url and just
let you enter the password git users after
a successful replication of open warehouse
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
named branch
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
and then modify the contents of the update, and submit it to the master branch
Now switch to branch branch
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
switch back to the master branch, merge
merge branch selected branch
more than a file created branch branch
to open three sentences to remove this update
to resolve the conflict
submitted to the master
success
In operation git IDEA
Configure git
Create a new project gitTest
search configuration settings in the git path test can be used to try and choose OK after configuring
create a class in src, just write something
Create a local warehouse
Create a local warehouse in the VCS in
selecting the parent directory of the current project IdeaProjects, select ok
after viewing the directory, you will find more of .git directory
Adding to the staging area
Right idea to add the project back to the staging area
Submit to the warehouse
Click on the top right corner of the green check mark to submit IDEA
selection src and .imi configuration file, and then add comments, submit
the code before adding will be marked green
Pushed to the remote repository
From VCS-> git-> push
clicks define remote, remote copy url githunb warehouse
click push, will be asked to enter a GitHub account and password
here I push failed, seemingly due to inconsistent versions reason, I re-create a warehouse
in accordance with the prior step push to get this warehouse, a success -
refresh the remote repository also find updated
Cloned from a remote repository
Copy githunb warehouse https url address to
all the way to choose yes and next, clone successfully
add a line of code, submit, push
open the github updated
Pulled from a remote repository
Open the old code beginning
click on the pull
pull success
Use branch
Create
create a branch called dev
at this time of the current branch is dev, label on which branch, which is the current branch
to add a method
to submit
click checkout back to the master
at this time there are no methods dev