Bootstrap

Git 常用记录

最小配置

其实就是一个账号

system 管理系统

global 管理当前系统用户

local 管理当前仓库

git config --global --list
git config --global user.name | user.email

工作区,暂存区,版本控制

工作区 ---> xxx <---暂存区 ---> 版本控制

git add -A 提交所有
git add .
git add 

git add -u

修改,删除文件

git mv  
git rm 

查看历史版本

git log
git log --oneline -n1
git log --oneline -1
git log --graph --all
git help --web log

删除分支

git branch -d 
# 强删
git branch -D 

修改历史记录

tips:

只在未提交代码前, 跟人电脑上玩次操作!

变更最近一次的commit

git commit --amend

变更多次commit

git rebase -i [commit hash-code] | git rebase -i --root
# 进入vim的交互模式
reword

合并多次commit

git rebase -i [commit hash-code] | git rebase -i --root
# 同上
squash

vim编辑器使用

nano编辑最小使用

修改内容;
保存修改内容三步走:
1. Crtl + O
2. Enter
3. Ctrl + X

Diff比较

# 比较的是暂存区和工作区的代码差异
git diff 
# 比较暂存区和HEAD的代码差异
git diff --cached

还原文件操作

# 只将暂存区的代码恢复至 HEAD, 并将修改的代码保留在工作区
git reset HEAD 
# 只将工作区的代码恢复至 HEAD
git checkout -- 

暂存当前任务

git stash --list
git stash 
git stash pop
git stash apply
git stash clear
...

拉取远程代码时,减少merge

git stash
git pull --rebase
git stash pop
# do sth
# go on

小结:

学习git的最佳实践, 了解其基本概念和原理, 然后按需学习, 并且实践!