The article will be added in succession, the learning page from http://www.liaoxuefeng.com/wiki/0013739516305929606dd18361248578c67b8067c8c017b000
To create a version library
Initialize a git repository, using git init
commands.
Add files to the Git repository in two steps:
The first step, use the command git add <file>
, note, can be used repeatedly, add multiple files;
The second step, using git commit
the command, is done.
Time Travel Machine
To keep track of the status of your workspace, use the git status
command.
If git status
you are told that a file has been modified, you git diff
can view the modified content.
Version fallback
HEAD
The point is the current version, so git allows us to navigate between versions of history, using commands git reset --hard commit_id
.
Before you travel, git log
you can view the commit history to determine which version to fallback to.
To return to the future, use the git reflog
view command history to determine which version to return to in the future.
Workspaces and Staging Area
Staging area is a very important concept of git, figuring out staging area, figuring out what a lot of git's operations are doing.
Manage changes
Understand how git keeps track of changes, each time it is modified, and if it doesn't add
get to staging area, it won't join commit
in.
Undo Changes
Scenario 1: When you mess up the contents of a file in your workspace and want to discard the workspace changes directly, use the command git checkout -- file
.
Scenario 2: When you not only changed the contents of a file in the workspace, but also added to the staging area, want to discard the changes, two steps, the first step with the command git reset HEAD file
, back to Scene 1, the second step by scene 1 operation.
Scenario 3: When an inappropriate modification to the repository has been submitted, you want to revoke this commit, refer to the version fallback section, but only if it is not pushed to the remote library.
deleting files
Command git rm
to delete a file. If a file has been submitted to the repository, then you never have to worry about accidentally deleting it, but be careful that you can only recover files to the latest version and you will lose what you modified after the last commit .
To add a remote library
To associate a remote library, use the command git remote add origin [email protected]:path/repo-name.git
;
Once associated, use the command to git push -u origin master
push all the contents of the master branch for the first time;
Thereafter, after each local submission, whenever necessary, you can use the command to git push origin master
push the latest changes;
One of the biggest benefits of distributed version systems is that working locally does not have to take into account the existence of remote libraries, which means that there is no Internet connection that works, and SVN refuses to work when it is not connected! When there is a network, and then the local submission push a bit to complete the synchronization, it is very convenient!
Cloning from a remote library
To clone a warehouse, you must first know the address of the warehouse and then use the git clone
command clone.
GIT supports a variety of protocols, including https
, but with the fastest ssh
supported native git
protocols.
Create and Merge Branches
GIT encourages the use of branching:
To view branches:git branch
To create a branch:git branch <name>
To switch branches:git checkout <name>
Create + switch Branches:git checkout -b <name>
Merge a branch to the current branch:git merge <name>
To delete a branch:git branch -d <name>
git-Common Command Collection