# git操作

  • git
  • commit 规范
  • sourceTree
  • 合并多条 commit
  • git stash
  • git commit --amend
  • gitemoji
  • cherry-pick

# git

# commit 规范

commitizen是一个nodejs命令行工具,通过交互的方式,生成符合规范的git commit,使用如下

git add .
git cz

# 如何安装

// 全局安装
npm install -g commitizen 
// 或本地安装
$ npm install --save-dev commitizen
// 安装适配器
npm install cz-conventional-changelog

# sourceTree

  • 便于查看分支图表
  • Dark 主题

# 合并多条 commit

# git rebase

演示地址 (opens new window)

参考这一次彻底搞懂 Git Rebase (opens new window)完美生活:git rebase -i | Linux 中国 (opens new window)【Git】rebase 用法小结 (opens new window)

git rebase -i head~3 // 合并最近三条commit

弹出编辑界面

pick b931dac 修改test2为test pick efd10a0 feat: 群引流加好友时间 pick 860aea3 合并

# commands

pick:保留该commit(缩写:p)

reword:保留该commit,但我需要修改该commit的注释(缩写:r)

edit:保留该commit, 但我要停下来修改该提交(不仅仅修改注释)(缩写:e)

squash:将该commit和前一个commit合并(缩写:s)

fixup:将该commit和前一个commit合并,但我不要保留该提交的注释信息(缩写:f)

exec:执行shell命令(缩写:x)

drop:我要丢弃该commit(缩写:d)

我一般选择rff命令,使用最上面的提交并修改,后两条合并,然后继续进入编辑界面修改提交记录,:wq 退出

# git reset --soft [commitID]

--soft 参数的区别在于把改动内容添加到暂存区 相当于执行了git add .

# git stash

场景:正在feature分支写代码时,线上出现bug,需要切回master修复

git stash
git checkout master
// 修复中...
git checkout <feture_branch> //切换刚才功能开发的分支
git stash pop //取出修改

# git commit --amend

修改git提交记录用法详解 (opens new window)

# 拉取本地不存在的远程分支

git checkout -b 1.0 origin/1.0
git pull

# gitemoji

https://gitmoji.js.org/

# cherry-pick

git cherry-pick 教程 (opens new window)

如有冲突则解决冲突后 git add . git cherry-pick --continue

rebase、merge、cherry-pick 都有 --abort(相当于反悔,回到操作之前的状态)

# 一些问题

1、2021.8.14 github修改密码校验为 token 校验

  • https://blog.csdn.net/weixin_41010198/article/details/119698015

  • https://blog.csdn.net/m0_46332820/article/details/119708248

2、怎么配置命令行代理

// 配置代理:
git config --global http.proxy <代理地址>
// 用完重置:
git config --global --unset http.proxy

3、cd ..cd - 有什么区别

  • cd..:返回到上一级目录
  • cd -:返回到上一次的工作目录

4、git add .git add -A的区别

  • git add .:将修改和新增的文件添加到暂存区
  • git add -A:将修改,新增和删除的文件添加到暂存区(方便恢复被删除的文件)
最后更新时间: 10/14/2022, 2:59:06 PM