branch

查看分支

列出本地所有的分支

git branch 

查看分支详细信息,列出本地所有的分支, + hash 信息

git branch -v

分支合并行为可视化

为了方便查看分支来源,比如大型项目通常会有多个分支以及分支合并的行为,单纯的使用终端查看分支来源、log并不直观。如果发生分支合并的异常行为,需要溯源,直观的观察git分支是必须的一个审计行为。

我看有推荐github desktop, source treeGitKraken(收费),但是之前上班的时候看师傅用的IDEA GIT分支图也有不错的效果,基本Jetbrain的所有IDE都有这个插件。点击菜单栏的git->log

pycharm_git_log

查看分支与远程的关联

git branch -vv #列出本地所有的分支, + hash 信息 + 与远程的关联信息

虽然默认本地和远程大部分都是同名的, 但是在多分支的场景下还是会出现不同名的情况
通过这个命令进行确认, 非常好用.

查看所有分支

列出所有的分支(远程和本地)这个命令在拉取别人的分支的时候非常有用, 比如

git branch -a

git branch -a | grep xxx

切换分支

# `-b` means create a new branch
git checkout -b new-branch-name
git checkout <commit-hash>

Detached HEAD 和 checkout commit然后修改入新branch

In Git, a detached HEAD state occurs when you are working directly on a specific commit(not the lastest) rather than on the latest commit of a branch. This can happen when you checkout a commit, a tag, or a remote branch directly, without creating a new branch.

HEAD is a pointer in Git that typically points to the latest commit on the current branch.


Welcome to point out the mistakes and faults!