1. 程式人生 > 其它 >力扣 - 劍指 Offer 55 - I. 二叉樹的深度

力扣 - 劍指 Offer 55 - I. 二叉樹的深度

一、git commit --amend

本地修改檔案,並提交:

git add .

git commit -m "message"

此時:

  如果發現 message 漏掉了一些資訊,可以使用:

    git commit --amend -m "message ++++++++++ other message"

  如果發現有額外的檔案漏掉,需要補充在上次的提交裡,可以使用: 

    git add .

    git commit --amend --no-edit

  如果需要同時修改message,並提交檔案,可以使用

    git add .

    git commit --amend -m "補充遺漏檔案 message.file "

通過git commit --amend可以避免生成無用的 commit-id,簡化git log的記錄,便於追蹤。

二、git rebase -i HEAD~n

如果有多次提交,此時想合併 commit-id,可以使用:git rebase -i HEAD~n

例子:

git log:看到有下面三次提交
"test3"
"test2"
"tes t1"

git rebase -i HEAD~3

生成:
pick 9e3c5b3a tes t1 pick ac139d94 test2 pick 2d0f7f64 test3 # Rebase 73a555fb..2d0f7f64 onto 73a555fb (3 commands) # # Commands: # p, pick
<commit> = use commit # r, reword <commit> = use commit, but edit the commit message # e, edit <commit> = use commit, but stop for amending # s, squash <commit> = use commit, but meld into previous commit # f, fixup <commit> = like "squash", but discard this commit's log message # x, exec
<command> = run command (the rest of the line) using shell # b, break = stop here (continue rebase later with 'git rebase --continue') # d, drop <commit> = remove commit # l, label <label> = label current HEAD with a name # t, reset <label> = reset HEAD to a label # m, merge [-C <commit> | -c <commit>] <label> [# <oneline>] # . create a merge commit using the original merge commit's # . message (or the oneline, if no original merge commit was # . specified). Use -c <commit> to reword the commit message. # # 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

合併 commit-id 最常用的是 squash 和 fixup, 前者包含 commit message,後者不包含。

修改vim檔案為:
pick 9e3c5b3a tes t1
s ac139d94 test2
f 2d0f7f64 test3
wq儲存退出
上述表示:test3合併到test2,且不保留log message;test2合併到tes t1,保留commit
生成:
# This is a combination of 3 commits.
# This is the 1st commit message:

tes t1

# This is the commit message #2:

test2

# The commit message #3 will be skipped:

# test3

# Please enter the commit message for your changes. Lines starting

此時,可以修改 tes t1 和 test2 這兩次commit的log。刪掉test2,tes t1修改為test5678。儲存退出。

git log:
只有一條 test5678 log message,而tes t1,test2,test3 這三次修改的內容也被合併了。