記錄git rebase用法

git 是基於文件系統的版本管理工具,文檔和詳細介紹能夠查看gitgit

一.git commit --amend

若是你對文件作了修改須要和上一次的修改合併爲一個changeshell

git add .
git commit --amend

二.git rebase

  在 Git 中整合來自不一樣分支的修改主要有兩種方法:merge 以及 rebase。 在本節中咱們將學習什麼是「變基」,怎樣使用「變基」,並將展現該操做的驚豔之處,以及指出在何種狀況下你應避免使用它 --  參考https://git-scm.com/book/zh/v2/Git-%E5%88%86%E6%94%AF-%E5%8F%98%E5%9F%BA工具

git rebase -i HEAD~n

列出最近的幾回change(從old -> new),而且左邊包含能夠進行的操做學習

  1 pick 7a802ef test4
  2 pick 0eaa6ba for #noTicket 1
  3 pick 999e310 for #noTicket
  4 pick 83bb011 for #ceshi
  5
  6 # Rebase c3ff658..83bb011 onto c3ff658 (4 command(s))
  7 #
  8 # Commands:
  9 # p, pick = use commit
 10 # r, reword = use commit, but edit the commit message
 11 # e, edit = use commit, but stop for amending
 12 # s, squash = use commit, but meld into previous commit
 13 # f, fixup = like "squash", but discard this commit's log message
 14 # x, exec = run command (the rest of the line) using shell
 15 #
 16 # These lines can be re-ordered; they are executed from top to bottom.
 17 #
 18 # If you remove a line here THAT COMMIT WILL BE LOST.
 19 #
 20 # However, if you remove everything, the rebase will be aborted.
 21 #
 22 # Note that empty commits are commented out

在commands裏面包括了幾個命令,簡單介紹下測試

r, reword = use commit, but edit the commit message
簡單的理解就是修改此commit的commit message
  1 pick 7a802ef test4
  2 r 0eaa6ba for #noTicket 1
  3 pick 999e310 for #noTicket
  4 pick 83bb011 for #ceshi

保存後進入編輯commit message模式this

  1 for #noTicket 1
  2
  3 測試
  4
  5 Change-Id: Ia0542f3b9292df45213c567948ff6f797858426f

保存退出後對應change的message就修改爲功了spa

edit : use commit, but stop for amending 選取此commit,而且保存退出後提交的修改將amend此commitrest

  1 pick 7a802ef test4
  2 e 73c9c8f for #noTicket 1
  3 pick 5cc2966 for #noTicket
  4 pick 437ba25 for #ceshi

保存退出後:code

 gerrit-workshop git:(master) git rebase -i HEAD~4
Stopped at 73c9c8f1b281b8636ae990f58d1fba6260efb589... for #noTicket 1
You can amend the commit now, with

    git commit --amend

Once you are satisfied with your changes, run

    git rebase --continue

 以後作的修改再次amend後會基於這個commit
blog

git add . 將全部修改提交到暫存區

git commit --amend 將暫存區的修改提交到本地倉庫修改你剛纔選中的change

git rebase --continue 回到最初的狀態

第三個 squash use commit, but meld into previous commit ,將這個change合併到上一次change中,而且會保留這個change的message,至關於將兩個commit合併爲一個

第四個 fixup 和squash同樣,可是不會保留change的message

相關文章
相關標籤/搜索