使用 diff3 样式解冲突
git config --gloabal merge.conflictStyle diff3
git checkout --conflict=diff3
使用技巧
git clone 下载
git 默认全分支下载,数据对象多,下载时间长,占用存储多,可使用单分支克隆:
–single-branch 单分支克隆
–no-tags 不下载tags
浅克隆:
–depth=1 历史深度指定为1
–unshallow 恢复下载完整历史
git worktree
工作树并行开发
git log 提交历史和显示diff
查看历史提交: git log --pretty=fuller
终断图形显示历史树: git log --all --decorate --oneline --graph
查看某些行最后一次提交信息:git blame <commit_id> -L start,end -- file_path
特定提交信息检索:
git log --grep=<pattern>
git log -S<string>
git log -G<regrex>
查看主干提交的历史信息和diff信息:git log --first-parent -p -m
git stash 暂存变更
git stash -u
暂存已跟踪文件的变更
git stash pop
恢复最近一次暂存的变更,并从暂存变更列表找那个删除
git stash list
列出暂存的变更清单
适用于需要中断当前的工作处理其他工作的场合
git add -p 部分提交
git add -p changed_file_path
只提交当前文件中的部分改动
git commit -c 复用提交信息
git commit -c commit_id --date=now <--reset_author>
git push
推送可以增加Review信息,提高工作效率
git push remote_name HEAD:ref/for/branch_name%r=reviewer@email.com
git push remote_name HEAD:ref/for/branch_name%topic=topic_message
git push remote_name HEAD:ref/for/branch_name%submiit
git cherry-pick 拣选提交
git cherry_pick -m 1
可以对Merge提交进行拣选
自定义Git
可以自定义 git 命令别名和脚本,提高工作效率
可以自定义 git 钩子脚本(hooks:不同条件下的触发脚本 pre-commit等