Contents
[ References ]
[ 常用簡易操作 ]
想退掉 commit 怎麼做
$ git reset HEAD^
> 還沒使用mtk_repo upload至gerrit時,把某次提的commit退回至上一個HEAD
在local端開新Branch
$ git checkout -b <new-branch>
如果只要合併Branch中某個Commit
$ git checkout <commit-id>
$ git branch <branch-name>
[ 各種使用情境 ]
Merge & Fast Forward
$ git merge b-01 #Fast forward
$ git merge --no-ff b-01</pre> #Not fast forward
Git 的 Merge 與 Fast-Forward: 簡單明瞭的好文章
Rebase的意義
本地端:
遠端倉庫:
假設在這一條頻繁變動的Local/Remote Branch上,而今天
想要push一筆commit 166c86
到remote branch上
$ git push origin master
但因為遠端可能有一些昨天
其他人的commit be5a04a
,於是push就失敗了,若此時下達
$ git pull origin master
會產生一筆不必要
的Merge,用來將自己原先要push的commit,Merge在master branch上
這時候就可以使用rebase了,就不會多一個無謂的Merge
$ git reset HEAD^ #若要返回到git pull之前的狀態
$ git pull --rebase

git stash時帶上附註(tag)
git stash save --keep-index "<tag>"
–keep-index: 只stash unstaged file
,staged的file會保存下來
為什麼要signed-off-by?
Short answer: 為了證明Patch是你的
Long answer: 在Linux核心開發中,大多使用E-mail來溝通,並夾帶Patch,在E-mail寄來寄去的過程中,難以認定Patch的提交者,因此需要Signed-off-by來辨認patch作者。(也就是說,如果不走這個開發流程的話,其實signed-off-by並沒有必要)
P.S.使用 git commit -s
,在commit message中產生signed-off-by訊息
打包一大堆commit給別人 (Squash)
$ git rebase -i HEAD~[N] #N為commit筆數,取掉[]後輸入
會產生如下畫面
pick d94e78 Prepare the workbench for feature Z --- older commit
pick 4e9baa Cool implementation
pick afb581 Fix this and that
pick 643d0e Code cleanup
pick 87871a I'm ready!
pick 0c3317 Whoops, not yet...
pick 871adf OK, feature Z is fully implemented --- newer commit
[...]
將pick改成s,儲存
pick d94e78 Prepare the workbench for feature Z --- older commit
s 4e9baa Cool implementation
s afb581 Fix this and that
s 643d0e Code cleanup
s 87871a I'm ready!
s 0c3317 Whoops, not yet...
s 871adf OK, feature Z is fully implemented --- newer commit
[...]
整理commit message,再儲存,搞定
想改掉前兩筆的 commit 內容/commit message
$ git rebase -i '<commit ID you want>'
# 將你要改的commit前方,從pick改成edit
edit d5b46821cf [WCNCR00215247] spi: mtk_snor: add support for MTK SPI NOR controller
pick 9ab5f45952 [WCNCR00215247] arm: dts: enable MTK SPI NOR controller driver
$ git commit --amend ## 加上你要更改的 commit message 後存檔
$ git rebase --continue
沒有GIT control但是想倒 Patch
$ patch -p1 < xxxx.patch