1. Git Overview
The latest version of git is 2.0.2. We recommend that you use command line in Linux. Git -- version to view the current git version.
Compared with version controllers such as SVN and CVS, git does not need to log on to the server, that is, it can also be used offline.
Resources: http://gitref.org/
Git and GitHub:
Git is a version control system. Similar to SVN and CVS. GitHub is a website that provides git services to users. In this way, you don't need to deploy the Git system on your own, just register an account and use the GIT service they provide.
Ii. installation and configuration
Install: sudo apt-Get install git
Configuration: Two Methods
1. Command Line
Git config -- global user. Name = yourname
Git config -- global user. Email = youremail
Git config -- Global color. UI = true
2. Edit ~ /. Gitconfig File
Git config -- list to view configuration content
3. Create a repository (repo for short)
Initialization
Git Init (generate a hidden. Git folder, which can be viewed by LS-)
2. clone a project on the GitHub website
Git clone https://github.com/pythonhackers/pythonhackers.git
(The pythonhackers folder is generated in the current directory)
Iv. Common git commands
650) This. width = 650; "src =" http://s3.51cto.com/wyfs02/M02/4D/A6/wKiom1RWMvKg_u8NAAPo5AP95ro347.jpg "Title =" git.png "alt =" wkiom1rwmvkg_u8naapo5ap95ro347.jpg "/> For example: WD is short for working directory, stage & history. Our goal is to synchronize the code. py edited in WD to history. Stage is the middle layer of history and WD.
Git status [-S]
After the GIT status-s command is executed, the following code is generated:
Example: A test1.py
M test2.py
If column A is displayed, the test1.py version in stage and history is inconsistent. If column M is displayed, the test2.py version of WD and stage is inconsistent.
Execute echo '*~ '>. Gitignore can make git ignore ~ File, that is, some backup files.
Git Add code. py (WD-> stage) undo: git checkout code. py (stage-> WD)
Git commit-M 'update' (stage-> history) undo: git reset code. py (history-> stage)
Git commit-am 'second Update' (WD-> history) undo: git checkout head code. py (history-> WD)
Git diff (view the code difference between stage and WD)
Git diff-staged (view the code difference of History & stage)
GIF diff head (view the code differences of History & WD)
Notice: git diff -- stat can output brief diff information.
Remove files and change file names
Note: git does not recognize the file name, but only the file content. Even if the file is renamed with the same content, it is considered unchanged.
Git RM old. py
Git Rm -- cached code. py (retain code. py of WD and delete code. py in stage)
Git MV old.txt old.doc (if the content is the same, it is still considered unchanged)
It is equivalent to the following command:
Git Rm -- cached old.txt
MV old.txt old.doc
Git add old.doc
Notice: git automatically determines whether the file content is changed and does not bind the file name to the file content.
Situation: when you are modifying the code. py code, someone will tell you that your previous code. py has a bug. What should I do? I am modifying code. py, but the Code has not been tested. I need to go back to the original code. py and change it to go online again. At this time, you can use
Git stash (clean up the current desktop and roll back to the original status. After fixing, take out the desktop and continue code)
Git stash list
Git stash pop
The history we mentioned above is actually a commit object, which can be accessed through a 40-byte hash code.
Git log (-- oneline) outputs the repository log.
Powerful command: git cat-file [-T,-p] [hash code or object]
-T output type: commit, tree, and blog types
-P: output the file content.
For example, git cat-file-T head (Head ~ *) (* Is a positive integer)
Git rev-Parse head outputs a 40-byte hash of the head.
Git rev-Parse head/Master (when there is only one branch, the head is equivalent to the master)
In addition, head ~ 4 ^ {tree}, head ~ 4: code. py (the path starts from the root directory, that is, the directory where. Git is located)
Cat-file-P equals show
The preceding content belongs to the tree-ish part.
Create another branch: If you have a new idea, but you don't want to code it under the current master branch, because you are not sure yet. At this time, you can:
Git branch tryidea
Git branch allows you to view all branches of the current project:
* Master
Tryidea
3. Switch to the tryidea branch through git checkout tryidea: Run git branch again: there will be:
Master
* Tryidea
You can also directly run git branch-B tryidea at the time of creation, that is, switch to tryidea while creating a new one.
Delete branch: git branch-D tryidea (provided that you have moved the content of the tryidea branch to the master Branch)
Git merge tryidea
Two types:
Fast-forward: only the content of the tryidea branch is modified.
3-way merge: both master and tryidea are modified.
Attach two logical diagrams of the commit object:
650) This. width = 650; "src =" http://s3.51cto.com/wyfs02/M02/4D/A5/wKioL1RWPKrgeXVhAAO1YpiQsyo817.jpg "style =" float: none; "Title =" commit .jpg "alt =" wkiol1rwpkrgexvhaao1ypiqsyo817.jpg "/>
650) This. width = 650; "src =" http://s3.51cto.com/wyfs02/M02/4D/A6/wKiom1RWPFbC53HlAAPcXOktk-A170.jpg "style =" float: none; "Title =" commit has.png "alt =" wKiom1RWPFbC53HlAAPcXOktk-A170.jpg "/>
.
This article is from the "blue fin dolphin" blog, please be sure to keep this source http://likunheng.blog.51cto.com/9527645/1571028
Git version controller is easy to use