git branch 分支
-
列出所有分支(本地)
git branch -
列出所有分支(包括远程)
git branch -a -
删除分支
git branch -d [branch]
git checkout 分支
-
切换到分支
git checkout develop -
创建并切换到分支
git checkout -b debug- 基于特定 commit 创建新分支new并切换到new分支
git checkout -b new <commit>
- 基于特定 commit 创建新分支new并切换到new分支
-
clone 远程仓库分支并切花到分支
git checkout -b develop origin/develop
git checkout – 撤销回退修改
- 撤销工作区的修改(恢复到暂存区状态或历史区,也就是把红色的修改撤销,但不能删除新增加的文件)
git checkout – .
git cherry-pick 合并
- 合并单个commit到当前分支
git cherry-pick <commit>
git clean
- 强制移除工作区所有新增加的文件夹和文件
git clean -df
git config 配置
-
查看配置信息
git config --list -
解决gitk中文乱码问题
git config --global gui.encoding “utf-8” -
修改提交编码
git config --global i18n.commitEncoding “{utf-8|gbk}”
git merge 合并
-
合并指定分支到当前分支
git merge develop- 不直接commit
git merge --no-commit develop
- 不直接commit
-
取消merge
git merge --abort -
不显示log
git merge – squash -
基于特定 commit 合并 develop 分支到 master 分支
- 切换到develop分支
git checkout develop - 基于特定 commit 创建一个新分支new
git checkout -b new <commit> - 切换到master分支
git checkout master - 合并new分支到master分支
git merge new - 删除new分支
git branch -d new
- 切换到develop分支
-
解决冲突
as -> VCS -> Git -> Resolve Conflicts…
git rebase 合并
-
合并指定分支到当前分支(合并时间线,)
git rebase develop -
合并develop分支几个连续commit到master
- 切换到develop分支
git checkout develop - 基于最后一个需要合并的 commit 创建一个新分支new
git checkout -b new <commit> - 从第一个需要合并的commit开始rebase这个新分支的commit到master
git rebase --onto master <commit>
- 切换到develop分支
git reflog 查看操作
- 查看所有的提交和分支切换信息
git reflog
git tag 打标签
- 显示所有的tag
git tag - 查看某个版本系统的tag
git tag -l ’ v1.0.*’ - 创建标签
第一种: git tag -a v1.0.0 -m ‘内容’
第二种: git tag v1.0.0 - 查看标签的详情
git show v1.0.0 - 推送标签
git push origin v1.0.0 - 删除本地标签
git tag -d v1.0.0 - 删除远程标签
git push origin :refs/tags/v1.0.0
git reset 撤销回退
-
回退到某个commit
- –mixed 修改版本库,修改暂存区,保留工作区(默认是这个)
git reset --mixed <commit> - –soft 修改版本库,保留暂存区,保留工作区
git reset --soft <commit> - –hard 修改版本库,修改暂存区,修改工作区
git reset --hard <commit>
- –mixed 修改版本库,修改暂存区,保留工作区(默认是这个)
-
暂存区到工作区
git reset HEAD . (类似get reset --mixed HEAD) -
撤销最近一次Commit
git reset HEAD^
git 回撤第一条提交记录
- git 回撤第一条提交记录
git stash 保存修改
-
保存工作区或者暂存区的修改以便切换分支
git stash -
查看所有的保存
git stash list -
恢复工作区或者暂存区的修改
git stash apply
远程同步
-
添加远程仓库
git remote add origin xxx.git -
取回远程仓库的变化,并与本地分支合并
git pull [remote] [branch] -
将远程主机的某个分支的更新取回,并与本地指定的分支合并,完整格式可表示为:
git pull <远程主机名> <远程分支名>:<本地分支名> -
本地回退Commit后强制推送到远程
git push -f -
推送到远程
git push -u origin master
Personal Access Token
- 新仓库在clone的时候就输入账号和Person Access Token即可
$ git clone https://github.com/username/repo.git
Username: your_username // 你的用户名
Password: your_token // 你的Personal Access Token
- 已有仓库使用Personal Access Token
git config --system --unset credential.helper //不保存密码
git config --global credential.helper store //保存密码
对比
- 分支对比
git log --left-right develop…release 2边不一样的commit,左箭头 < 表示是 dev 的,右箭头 > 表示是 release的
git log develop ^release 查看 dev中log有的commit,而 release中log没有的commit
git diff develop origin/develop --stat 显示出所有有差异的文件(不详细,没有对比内容) - 对比工具对比
git difftool
别名
-
显示 Log 信息
git config --global alias.lg “log --color --graph --pretty=format:‘%Cred%h%Creset%C(yellow)%d%Creset%s%Cgreen(%cd)%C(bold blue)<%an>%Creset’ --abbrev-commit --date=format:‘%Y-%m-%d’”
git config --global alias.lg “log --graph --decorate --oneline --pretty=format:‘%Cred%h - %C(bold white) %s %Creset %C(yellow)%d %C(cyan) <%cd> %Creset %Cgreen(%cn)’ --abbrev-commit --date=format:‘%Y-%m-%d’”
git config --global alias.lg “log --color --graph --pretty=format:‘%Cred%h%Creset%C(yellow)%d%Cgreen(%cd)%Creset%s%C(bold blue)<%an>%Creset’ --abbrev-commit --date=format:‘%Y-%m-%d’” -
显示所有分支 Log 信息
git config --global alias.la “log --all --color --graph --pretty=format:‘%Cred%h%Creset%C(yellow)%d%Creset%s%Cgreen(%cd)%C(bold blue)<%an>%Creset’ --abbrev-commit --date=format:‘%Y-%m-%d’”
工具
-
git查看有哪些对比工具可以设置命令
git difftool --tool-help -
设置对比工具
git config --global diff.tool bc3
git config --global difftool.bc3.path “C:\Program Files (x86)\Beyond Compare 3\BCompare.exe” -
设置合并工具
git config --global merge.tool bc3
git config --global mergetool.bc3.path “C:\Program Files (x86)\Beyond Compare 3/BCompare.exe”
您的姓名和邮件地址基于登录名和主机名进行了自动设置。请检查它们正确
与否。您可以对其进行设置以免再出现本提示信息:
git config --global user.name "Your Name"
git config --global user.email you@example.com
设置完毕后,您可以用下面的命令来修正本次提交所使用的用户身份:
git commit --amend --reset-author