Please reprint from the source: http://eksliang.iteye.com/blog/2249305
1. Introduction
git is a distributed version management system open sourced by linus in 2005;
SVN and CVS: It is centralized and must be connected to the Internet to work; if the version library hangs, it cannot work;
For more detailed introduction reference: http://www.liaoxuefeng.com
git download address: http://git-scm.com
2. Git creates a repository (repository)
2.1. The first way: init
Just enter a directory and execute the git init command to create a repository; after initialization, a .git hidden folder will be generated under the current directory; this .git folder is the repository, and the execution command is as follows:
$ git init
2.2. The second way: clone
Use clone, for example, clone dubbo's project to local, the code is as follows:
$ git clone https://github.com/alibaba/dubbo.git Cloning into 'dubbo'... remote: Counting objects: 43552, done. remote: Compressing objects: 100% (2/2), done. Receiving objects: 19% (8275/43552), 3.30 MiB | 154.00 KiB/s ....
2. git global variable settings
git config --global user.name xialiang #Set username git config --global user.email [email protected] #Set mailbox git config --global color.ui true #Display commands with style git config --list #Get Git configuration information #These global configurations will be persisted to a file, and you can also operate this file directly, with the same effect cat ~/.gitconfig
3. Add and submit documents
#Create a new file, this file will be stored in the workspace vim test #Add this file to the staging area git add test git add -A #Add all files in the workspace to the staging area #Commit the files in the staging area to the repository git commit -m ‘add test file’ #-m is followed by the remark information of this submission. If you submit it directly by git commit, an editor will be opened for us to fill in the remarks; git commit -am 'commit all' #Commit all files to the repository at one time, note that new files in the workspace must go to git add before they can be added to the repository #After submitting the file, view the submitted history information git log
4. Check git status
#View the status of the current workspace git status #The abbreviation above, the display is more concise git status -s
5. View file differences
#View the difference between the files in the workspace and the staging area git diff #View the difference between the files in the staging area and the version library git diff --staged (I prefer this) git diff --cached #View the difference between the files in the repository and the files in the workspace git diff head
As shown below:
Test: After adding the file modification in the repository to the staging area, make the modification again; at this time, the viewing status should be like this
$ git status -s MM testUse git diff , git diff head , git diff --staged to compare
6. Undo operation
#Roll back the files in the workspace to the state of the last git commit (roll back to the repository) or git add (roll back to the staging area). git checkout fileName #Roll back the files in the workspace or staging area to the state of the last git commit (roll back to the repository) git checkout head filename #This command can either roll back the version or roll back the modification of the temporary storage area to the workspace git reset
Tips:
There are two cases for git checkout fileName:
One is that the file has not been placed in the temporary storage area since it was modified. Now, undoing the modification will return to the same state as the version library;
One is that after the file has been added to the staging area, it has been modified. Now, undoing the modification will return to the state after adding it to the staging area.
7. Delete and rename files
#delete version file git rm fileName #delete file after submission git commit #Delete the repository, but keep the files in the workspace, you can use git reset to roll back git rm --cached fileName #Commit at this time, the file will exist in the workspace git commit #rename file git mv oldFile newFile git commit For example, modify aa to aa.txt git mv aa aa.txt git commit -m 'mv aa'