Theme NexT works best with JavaScript enabled
1. 设置 1.1. 查看 $ git config --list $ git config --list --global $ git config --list --local
1.2. 最小设置 $ git config --global user.name "xxx" $ git config --global user.email "xxx@email.com"
1.3. 代理加速 $ git config --global http.proxy socks5://127.0.0.1:1234 $ git config --global https.proxy socks5://127.0.0.1:1234 $ git config --global http.sslVerify false $ git config --global --unset http.proxy $ git config --global --unset https.proxy $ git config --global http.sslVerify true
1.4. 命令别名 $ git config --global alias.st status $ git st $ vim ~/.gitconfig $ source ~/.gitconfig
[alias] st = status co = checkout ci = commit br = branch unstage = "reset HEAD" last = "log -n1" lg = "log -n10 --color --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit"
2. 常用命令 2.1. 克隆及更新(clone、pull、fetch) $ git clone xxx.git $ git clone xxx.git "指定目录" $ git clone -b <new_branch_name> xxx.git $ git pull $ git pull origin master $ git pull origin master:master $ git fetch --all $ git fetch origin master
2.2. 提交(add、commit、push) $ git add <.|file|dir> $ git commit -m ["本次提交的备注信息" ] $ git commit file1[file2 file3 ...] -m [message] $ git push origin master $ git push --tags
2.3. 分支(branch) $ git branch $ git branch -r $ git branch -a $ git checkout -b <branch_name> $ git checkout -b <branch_name> <remote_branch|remote_tag> $ git checkout -t origin/dev $ git branch <branch_name> $ git branch -D <branch_name> $ git push origin -d <branchname> $ git checkout master
2.4. 标签(tag) $ git tag $ git tag <tag_name> $ git tag <tag_name> <commit_id> $ git tag -d <tag_name> $ git push origin <tag_name> $ git show <tag_name> $ git checkout -b <branch_name> <tag_name>
2.5. 查询提交记录(log) $ git log $ git log --all $ git log --oneline $ git log --graph $ git log -n5 $ git log <branch_name> $ git log <file1> $ git log -p <file1> $ git blame <file1>
2.6. 撤销与回退(reset) $ git reset HEAD <file1>... $ git checkout <file1>... $ git checkout . $ git reset --soft <commit_id> $ git reset --mixed <commit_id> $ git reset --hard <commit_id>
2.7. 查询远程仓库(remote) $ git remote $ git remote -v $ git remote add <url> $ git remote show <remote_name>
2.8. 合并及冲突处理(merge) $ git merge master 在当前分支上合并master分支过来 $ git merge --no-ff origin/dev 在当前分支上合并远程分支dev $ git merge --abort 终止本次merge,并回到merge前的状态
2.9. 文件差异比较(diff) $ git diff [-- file1 file2 ...] $ git diff HEAD $ git diff --cached $ git diff <branch_name> $ git diff commit_id
2.10. 重命名文件(mv) $ git mv README.md README_2.md
2.11. 删除文件(rm)
2.12. 使用暂存(stash)加塞其它紧急任务 $ git stash $ git stash list $ git stash apply [stash num] $ git stash pop [stash num] $ git stash show [stash num] $ git stash drop [stash num] $ git stash clear
3. 更多学习资源推荐