Git 使用技巧
多個commit壓縮成一個,官方說法–重寫歷史
? ? ? ? 多人進行項目協同開發時,如果大家都有多次提交,這樣在合并的時候如果有沖突解決起來步驟就會很繁瑣,一次次的解決,rebase --continue……,在跨團隊的情況下體驗更是糟糕,甚至會出現代碼丟失的風險,如果我們能將自己的多次提交壓縮成一個,那么在合并的時候只需處理一次沖突,這樣就方便很多
方法一:
? ? ? ? git rebase -i head~n
? ? ? ? 例如:我想給自己的三次提交壓縮成一個,輸入git rebase -i head~3,運行這個命令會在文本編輯器上給你一個提交的列表,看起來像下面這樣:
pick f7f3f6d changed my name a bit pick 310154e updated README formatting and added blame pick a5f4a0d added cat-file? ? ? ? 中間部分是commit id ,后面部分是commit message,前面pick就是選擇的意思,保留你想使用的commit message 丟棄掉其余的commit則使用f,更多的選項使用方法和解釋如下
# 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方法二
? ? ? ? git rebase -i?f7f3f6d
? ? ? ? 后面是commit id,這樣會把此id之后的所有提交壓縮成一個,輸入這個命令后像上面一樣會在文本編輯器上給你一個提交的列表,后面操作如上
? ? ? ? 更多的使用方法及解釋請參考Git-重寫歷史
總結
- 上一篇: h sm2 曲线参数_磁测量常用专业术语
- 下一篇: idea关联git