type
status
date
slug
summary
tags
category
password
icon

checkout

  • 移动 HEAD,让它指向某个 commit 或某个 branch。
  • checkout --detach :让 HEAD 脱离当前 branch,直接指向下⾯的 commit。

rebase

把当前 commit(以及它之前的 commits)应⽤到指定的需要 rebase 的 commit 上。
Git 中的每⼀个 commit 都是不会改变的,所以 rebase 之后的每个 commit 都是新产⽣的,⽽不是对原先的 commit 进⾏「修改」
notion image

rebase 冲突

rebase 的冲突解决⽅法和 merge 冲突⼀样,只是把 git merge --continue 改成 git rebase --continue 就⾏了

reset

把当前 branch 指向指定的 commit。
  • git reset 指定commit 移动到指定 commit,并保留 working tree 的内容
  • git reset --hard 指定commit 移动到指定 commit,并重置 working tree
💡
reset 和 checkout 的区别
它们都是移动 HEAD,但 chekcout 移动的时候是⾃⼰移动,不带着 branch ⼀起;⽽ reset 会带着branch ⼀起移动

提交过的东⻄写错了

  1. 最新的⼀条内容需要修改: git commit --amend
「修改」只是概念⾏为,实质上会产⽣⼀个新的 commit
  1. 旧的内容需要修改:
    1. 交互式 rebase
      常⽤选项:
      • pick 或 p :沿⽤
      • reword 或 r :修改 commit message
      • edit 或 e :修改 commit 内容
      • drop 或 d :删除
      • squash 或 s :和上⼀条融合,并且合并 commit message(可编辑)
      • fixup 或 f :和上⼀条融合,并且沿⽤上⼀条的 commit message
  1. 已经 push 到 master 的内容需要删除: 不能⽤ rebase,因为 master 上的东⻄是不能强⾏修改的可以⽤ git revert 指定commit 来撤销。它的原理是创建⼀个新的 commit,内容是指定 commit 的「相反内容」
 

add -i 交互式 add

⽤法:
常⽤选项:
  • p (patch)
选取块时的常⽤选项:
  • y:选⽤当前块
  • n:不⽤当前块
  • s:把当前块做⾃动切分后再重新询问
  • e:⼿动选取修改内容

tag

另⼀种引⽤类型。
  • 和 branch 区别之⼀:不能改变
  • 和 branch 区别之⼆:不能被 HEAD 指向
  • ⽤处:设置持久标记,例如版本号
  • origin/master, origin/feature, origin/HEAD 和 tag 有相似之处:也不能从本地改变位置,也不能被 HEAD 指向

cherry-pick

⽤法:

⽤途:应⽤指定的某个或某些 commit 到 HEAD 处
  • ⽐如我想抛弃某个 branch,这个特性不要了,但它的某两个 commit 我希望保留
  • git cherry-pick 这两个 commit

reflog

⽤法:
notion image
⽤途:
查看指定的引⽤(HEAD 或 branch)的移动历史,从⽽找到之前的某个特定 commit
Feature BranchingGit Flow
Loading...
shuouyang
shuouyang
android开发 ReactNative开发 小程序开发
最新发布
AOSP 环境搭建
2025-3-29
View 绘制流程-源码解析
2025-3-12
HTTP
2025-3-4
JVM 虚拟机
2025-2-28
蓝牙-BLE-基础
2025-2-28
从 OkHttp 的原理来看 HTTP
2025-2-19
公告
🎉热点信息🎉
--- 1 ---
Jet Brains 推出新的跨平台支持 Kotlin MultiPlatform
--- 2 ---
新的小巧便捷的依赖注入框架 Koin
--- 3 ---
新一代 API 查询语言 GraphQL