1. Initial command
Init Initialize Warehouse
$ git init
Clone cloning Repository
$ git clone https://github.com/repname$ git clone https://github.com/repname Myrep # Myrep as the local warehouse name
Config configuration
$ git config--list #查看配置 $ git config--system user.name #系统级配置 $ git config--global User.Name #全 Board configuration, System user level $ git config user.name #仓库级配置
Help
$ git help <verb>git <verb>--help$ Mans git-<verb>
Remot Remote Warehouse
$ git remote-v #查看远程仓库
$ git Remote show Origin #查看远程仓库
$ git remote add PB https://github.com/pb #添加远程仓库
$ git remote rename PB Paul #重命名远程仓库
$ git remote rm Paul #移除远程仓库
2. Basic commands
Status View file state
$ git status
$ git status-s #状态简览
Add Staging Modified File
-A #暂存所有已修改文件
Commit to commit an update
$ git commit-m "commit message"$ git commit-a-M "Commit message" #跳过暂存区, submit directly
Push pushes to the remote repository
$ git push$ git push origin master
Fetch pull data from remote repository
$ git fetch [remote-name]
Merge Merging Branches
$ git merge
3. Common commands
Diff View changes
diff diff --staged #比较 Warehouse-Staging Area
Log View commit History
--stat #展示提交的简略统计信息
Undo Action
$ git Commit--amend #重新提交 $ git reset HEAD filename #取消暂存的文件
Checkout undo changes to a file
$ git checkout filename
# overwrites the workspace file
# If staging area has changed files, then from staging area to workspace
# If staging area files are not changed, then from the warehouse to the workspace
Tag tag
$ git tag -A v1. 4 " my version 1.4 #创建附注标签 $ git tag v1. 4 -a v1. 2 9fceb02 #对某次提交后期打标签 $ git push origin v1. 5 ---B version2 v2. 0.0 #检出标签
RM Remove Files from
$ git rm filename #个人感觉效果同 rm$ git rm--cached filename #移除暂存区中的文件
MV Moving files
$ git mv file_from file_to #个人感觉效果同 MV
Common GIT Commands