克隆
- 克隆项目
git clone https://github.com/spring-projects/spring-boot.git
- 克隆一个包含很多子模块的项目
git clone --recursive https://github.com/caffe2/caffe2
- 下载子模块
git submodule update --init --recursive
分支操作
-
查看远程及本地分支
git branch -a
-
将dev开发分支合并到master主分支中
git checkout master git merge dev
-
拉取远程分支到本地
git checkout -b branch01 origin/branch01
-
查看分支图
git log --graph --abbrev-commit --decorate --date=relative --all git log --graph --oneline --decorate --all git log --graph --date-order -C -M --pretty=format:'<%h> %ad [%an] %Cgreen%d%Creset %s' --all --date=short git log --graph --abbrev-commit --decorate --format=format:'%C(bold blue)%h%C(reset) - %C(bold green)(%ar)%C(reset) %C(white)%s%C(reset) %C(dim white)- %an%C(reset)%C(bold yellow)%d%C(reset)' --all git log --graph --abbrev-commit --decorate --format=format:'%C(bold blue)%h%C(reset) - %C(bold cyan)%aD%C(reset) %C(bold green)(%ar)%C(reset)%C(bold yellow)%d%C(reset)%n'' %C(white)%s%C(reset) %C(dim white)- %an%C(reset)' --all git log --graph --format=format:'%C(bold blue)%h%C(reset) - %C(bold green)(%ar)%C(reset) %C(white)%s%C(reset) %C(bold white)— %an%C(reset)%C(bold yellow)%d%C(reset)' --abbrev-commit --date=relative git log --graph --format=format:'%C(bold blue)%h%C(reset) - %C(bold cyan)%aD%C(reset) %C(bold green)(%ar)%C(reset)%C(bold yellow)%d%C(reset)%n'' %C(white)%s%C(reset) %C(bold white)— %an%C(reset)' --abbrev-commit git log --all --graph --pretty=format:'%C(auto)%h%C(auto)%d %s %C(dim white)(%aN, %ar)'
可以在~/.gitconfig文件中添加别名
[alias]
log1 = log --graph --abbrev-commit --decorate --date=relative --all
log2 = log --graph --oneline --decorate --all
log3 = log --graph --date-order -C -M --pretty=format:'<%h> %ad [%an] %Cgreen%d%Creset %s' --all --date=short
log4 = log --graph --abbrev-commit --decorate --format=format:'%C(bold blue)%h%C(reset) - %C(bold green)(%ar)%C(reset) %C(white)%s%C(reset) %C
log5 = log --graph --abbrev-commit --decorate --format=format:'%C(bold blue)%h%C(reset) - %C(bold cyan)%aD%C(reset) %C(bold green)(%ar)%C(rese
log6 = log --graph --format=format:'%C(bold blue)%h%C(reset) - %C(bold green)(%ar)%C(reset) %C(white)%s%C(reset) %C(bold white)— %an%C(reset)%
log7 = log --graph --format=format:'%C(bold blue)%h%C(reset) - %C(bold cyan)%aD%C(reset) %C(bold green)(%ar)%C(reset)%C(bold yellow)%d%C(reset
log8 = log --all --graph --pretty=format:'%C(auto)%h%C(auto)%d %s %C(dim white)(%aN, %ar)'
tree = !"git log3"
然后就可以直接在使用git tree, git log1, git log2 ...
暂存操作
- 把当前进度保存到暂存区
git stash
- 恢复最新的进度到工作区
git stash pop
撤销操作
- 撤销
git commit
但是未git push
的修改
- 使用
git log
找到你想撤销的commit_id git reset --hard commit_id
完成撤销,同时将代码恢复到前commit_id 对应的版本。git reset commit_id
完成git commit
命令的撤销,不对代码修改进行撤销,可以通过git commit
重新提交对本地代码的修改
未完待续...