修改commit歷史記錄
git rebase -i
git rebase 使用互動模式
要修改的commit,找到其init commit按右鍵 ->
Rebase children of bb0c9c2
interactively… ->
點選想修改的commit, 按 Edit Message
-> OK
結果: 造成蝴蝶效應
修改的那一點commit, 和其 children commit的index全部改變
指令: git rebase -i bb0c9c2
(C1的index)
意思: 修改從C6到C1的歷史訊息!
pick 7de7617 add pig
pick a252c2a add fish
# Rebase 1b8128c..a252c2a onto 1b8128c (2 command(s))
#
# Commands:
# p, pick = use commit
# r, reword = use commit, but edit the commit message
# e, edit = use commit, but stop for amending
# s, squash = use commit, but meld into previous commit
# f, fixup = like "squash", but discard this commit's log message
# x, exec = run command (the rest of the line) using shell
# d, drop = remove commit
#
# These lines can be re-ordered; they are executed from top to bottom.
#
# If you remove a line here THAT COMMIT WILL BE LOST.
#
# However, if you remove everything, the rebase will be aborted.
#
# Note that empty commits are commented out
~
~
"~/git-examples2/git-rebase/.git/rebase-merge/git-rebase-todo" 21L, 684C
任務: 想把cute animals移到pig的後面
要修改的commit,找到其init commit按右鍵 ->
Rebase children of bb0c9c2
interactively… ->
拖拉
或是點選上下
children commit的index受到影響
squash
同一組功能的修改commit一次就好
要修改的commit,找到其parent commit按右鍵 ->
Rebase children of bb0c9c2
interactively… ->
把add cat1
, add cat2
, add 2 cats
3個commit squash在一起
Squash with previous
把cat訊息
add 2 cats (+2 squashed commits)
Squashed commits:
[1de2076] add cat 2
[cd82f29] add cat 1
改成
add all cats
把dog訊息
add dog 2 (+1 squashed commit)
Squashed commits:
[0e131b6] add dog 1
改成
add all dogs
較簡潔
要修改的commit,找到其init commit按右鍵 ->
Rebase children of bb0c9c2
interactively… ->
勾選add all cats
的Amend Commit
->
HEAD
已經移到 add database settings
點選上一顆parent commit按右鍵 ->
提醒在rebase過程中,先在這個commit停下來
Reset current branch to this commit ->
Reset to Commit…
Using mode: Mixed - Keep working copy but reset index
按 add database settings
檢查當時的狀態
總共有 cat1.html, cat2.html, cat3.html, cat4.html
cat1.html, cat2.html => commit -m "add cat1 & cat2"
cat3.html, cat4.html => commit -m "add cat3 & cat4"
HEAD
已經移到 add cat3 & cat4
rebase 還沒完成,只是在中間的過程先調整
告訴後面的branch可以接回來了
(這個小節試了好多次,終於成功了!!開心)
or
or
By clicking below, you agree to our terms of service.
New to HackMD? Sign up
Syntax | Example | Reference | |
---|---|---|---|
# Header | Header | 基本排版 | |
- Unordered List |
|
||
1. Ordered List |
|
||
- [ ] Todo List |
|
||
> Blockquote | Blockquote |
||
**Bold font** | Bold font | ||
*Italics font* | Italics font | ||
~~Strikethrough~~ | |||
19^th^ | 19th | ||
H~2~O | H2O | ||
++Inserted text++ | Inserted text | ||
==Marked text== | Marked text | ||
[link text](https:// "title") | Link | ||
 | Image | ||
`Code` | Code |
在筆記中貼入程式碼 | |
```javascript var i = 0; ``` |
|
||
:smile: | ![]() |
Emoji list | |
{%youtube youtube_id %} | Externals | ||
$L^aT_eX$ | LaTeX | ||
:::info This is a alert area. ::: |
This is a alert area. |
On a scale of 0-10, how likely is it that you would recommend HackMD to your friends, family or business associates?
Please give us some advice and help us improve HackMD.
Do you want to remove this version name and description?
Syncing