查看分支的历史记录,缺省则默认是当前分支
$ git log zs_dev
commit 9bc97b9aa33ed2410defdd71a9889acb0b0c2a9f (HEAD -> zs_dev)
Author: zs <[email protected]>
article模块新增接口
将当前分支为提交的数据暂存起来,这个意思就是把add那些数据先保存起来,可以切换其他分支在吐出来
$ git stash
Saved working directory and index state WIP on zs_dev: 9bc97b9 article模块新增接口
$ git status
On branch zs_dev
Your branch is ahead of 'origin/zs_dev' by 16 commits.
(use "git push" to publish your local commits)
nothing to commit, working tree clean
$ git checkout master
Switched to branch 'master'
Your branch is up to date with 'origin/master'.
拉取远程分支
$ git pull origin master
remote: Enumerating objects: 115, done.
remote: Counting objects: 100% (115/115), done.
remote: Compressing objects: 100% (62/62), done.
remote: Total 81 (delta 24), reused 0 (delta 0), pack-reused 0
Unpacking objects: 100% (81/81), 10.02 KiB | 28.00 KiB/s, done.
查本地分支对应的远程分支当前的版本号
该命令可以用来查看本地分支对应的远程分支当前的版本号,就可以判断本地与远程版本的差异
$ git branch -vv
feature 613170d [origin/feature] Merge branch 'zs_dev' into feature
master 8a55722 [origin/master] 添加了测试接口
* zs_dev 613170d [origin/zs_dev: ahead 8] Merge branch 'zs_dev' into feature
查看本地分支当前版本号
查看本地分支的最后一次提交的版本号
$ git branch -v
feature 613170d Merge branch 'zs_dev' into feature
master 8a55722 添加了测试接口
* zs_dev 613170d [ahead 8] Merge branch 'zs_dev' into feature
查看哪些分支合并到当前分支
$ git branch --merged
feature
master
* zs_dev
查看所有未合并工作的分支
查看远程仓库有哪些分支
$ git branch -r
origin/cathy_dev
origin/feature
origin/hyx_dev
origin/master
origin/zs_dev
查看所有分支,包括远程和本地
$ git branch -a
feature
master
* zs_dev
remotes/origin/cathy_dev
remotes/origin/feature
remotes/origin/hyx_dev
remotes/origin/master
remotes/origin/zs_dev
删除本地分支
强制删除分支
重命名分支
不指定名字直接推送当前本地分支对应的远程分支
不指定名字直接拉取当前本地分支对应的远程分支
查看该文件与上一次提交的文件的差异
git stash save " stash remark " 存储是添加备注
当要恢复继续完善的时候 git stash pop / git stash apply 就可以恢复到当前的工作目录
将当前未提交的内容暂存起来,之后当前分支环境是一个干净的环境,可以进行分支切换合并的操作,间接保护未提交的内容,当合并分支时,防止数据覆盖,合并前使用git stash将未提交的文件暂存,合并后在使用git pop 弹出,如有弹出的文件与合并后的文件同时修改过,则需要解决冲突
由此可见,只有当前分支的git状态是干净的,也就是没有修改文件,或者是修改完未提交的,才可以进行分支切换操作
在使用场景1中,对master的a.txt文件进行修改后,存入暂存区后切换到hot-fix分支后,我们可以把a.txt文件从暂存区弹出,有冲突则解决冲突
解决完冲突在添加提交即可
查看当前分支的暂存列表,每执行一次git stash命令就暂存一次
$ git stash list
stash@{0}: WIP on zs_dev: 9bc97b9 article模块新增接口
$ git stash show
.gitignore | 5 ++++-
chaoshan-auth/src/main/resources/config/application-dev.yml | 2 +-
chaoshan-gateway/src/main/resources/config/application-dev.yml | 2 +-
3 files changed, 6 insertions(+), 3 deletions(-)
$ git stash show stash@{0}
.gitignore | 5 ++++-
chaoshan-auth/src/main/resources/config/application-dev.yml | 2 +-
chaoshan-gateway/src/main/resources/config/application-dev.yml | 2 +-
3 files changed, 6 insertions(+), 3 deletions(-)
显示第一个改动
应用某个存储但不会将存储从存储列表中删除,不指定存储名默认第一个
存储名缺省,默认弹出第一个存储,并将该缓存从缓存栈中删除
存储名缺省默认删除第一个存储
删除所有存储 危险操作
查看所有执行的历史命令
查看git命令帮助文档
1、git branch -a 查看本地版本库的所有分支列表
2、git fetch 同步本地与远程库的分支信息
3、git checkout -b 新起本地分支名 远程分支名 拉取新分支并切换
当前远程库中新增feature分支,需要将其拉取到本地并切换
Administrator /d/workspace_project/chaoshan-admin (zs_dev)
$ git branch -a
master
* zs_dev
remotes/origin/cathy_dev
remotes/origin/hyx_dev
remotes/origin/master
remotes/origin/zs_dev
Administrator /d/workspace_project/chaoshan-admin (zs_dev)
$ git fetch
From https://gitee.com/xiaoshuangstudy/chaoshan
* [new branch] feature -> origin/feature
Administrator /d/workspace_project/chaoshan-admin (zs_dev)
$ git branch -a
master
* zs_dev
remotes/origin/cathy_dev
remotes/origin/feature
remotes/origin/hyx_dev
remotes/origin/master
remotes/origin/zs_dev
Administrator /d/workspace_project/chaoshan-admin (zs_dev)
$ git checkout -b feature remotes/origin/feature
Switched to a new branch 'feature'
M chaoshan-auth/src/main/resources/config/application-dev.yml
M chaoshan-gateway/src/main/resources/config/application-dev.yml
Branch 'feature' set up to track remote branch 'feature' from 'origin'.
Administrator/d/workspace_project/chaoshan-admin (feature)
$ git branch
* feature
master
zs_dev
Administrator /d/workspace_project/chaoshan-admin (feature)