From 615467d28c629e9b20924213fefb08b8ebcadecc Mon Sep 17 00:00:00 2001 From: Mhrooz Date: Thu, 22 Aug 2024 20:13:03 +0200 Subject: [PATCH] add 2.9 notes --- notes/2.9-change_history.md | 51 +++++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 notes/2.9-change_history.md diff --git a/notes/2.9-change_history.md b/notes/2.9-change_history.md new file mode 100644 index 0000000..51ca371 --- /dev/null +++ b/notes/2.9-change_history.md @@ -0,0 +1,51 @@ +## 2.9 改变历史 + +### 2.9.1 悔棋 + +`git commit --amend -m` 会将当前的暂存区(staging area)中的更改与上一次的提交合并为一个新的提交,同时允许你修改提交信息。 + +```bash +git commit -amend -m "message" # 修改上次提交的message +``` + +添加一个误删的文件 +```bash +git checkout HEAD^ -- # 从上次的提交恢复文件 +git status +git commit --amend -m "message" # 将当前的修改添加到上次的提交中 +``` + +### 2.9.2 多步悔棋 + +想要将最近的两个提交压缩为一个,并把提交说明改为“modify hello.h”,可以使用如下方法进行操作。 + +```bash +git reset --soft HEAD^^ # 重置到两次提交之前 +git status +git commit -m "modify hello.h" +``` + +### 2.9.3 回到未来 git rebase + + +```bash +git cherry-pick # 从众多的提交中挑选出一个提交应用在当前的工作分支中 +``` + +去掉某个commit +```bash +git checkout # 先切换到某次提交 +git cherry-pick # 输入之后的提交 +git checkout # 再切换回来 +``` + +合并两次commit +```bash +git checkout [|] +git reset --soft HEAD^^ # 向前移动两次 +git commit -C C # 提交,重用C提交的提交说明 +git cherry-pick E +git cherry-pick F +``` + +