git rebase 简介
生活随笔
收集整理的這篇文章主要介紹了
git rebase 简介
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
前言
使用場景
主要功能是編輯git提交歷史,所以建議在私有分支使用!
rebase使用方法
1. 開始變基
git rebase -i master (不一定對比分支,也可以對比某個提交點)
執行命令后出現提交歷史:
pick 4daa490d 1 pick a996b550 ar pick 2b43e8b1 2 pick 8e71f26f as pick 37817519 3 pick 876680bd af pick 8ddef852 4 pick 631d56b5 ad pick 4814d62b 5 復制代碼2. 進行修改
往下拉會看見命令提示:
# 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 # 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>] 復制代碼解釋一下上面的命令:(完整提交 = 提交內容 + 提交日志)
pick:該提交保留 reword:提交內容不變,但是編輯提交日志 squash:提交內容和提交日志合并至上次提交(提交日志合并時可編輯) fixup:提交內容合并至上次提交,提交日志不合并(刪除提交日志) drop:刪除本次提交內容和提交日志 復制代碼單獨說一下edit這個命令:
回滾至當次提交(未提交狀態,保留提交內容) 然后你可以修改當次提交內容,可以添加或者拆分提交!(月光寶盒時光倒流功能) 修改完畢后執行:git rebase --continue 復制代碼3. 測試結果
假設修改設置如下:
pick 4daa490d 1 reword a996b550 ar pick 2b43e8b1 2 squash 8e71f26f as pick 37817519 3 fixup 876680bd af pick 8ddef852 4 drop 631d56b5 ad pick 4814d62b 5 復制代碼最終效果:
4daa490d 1 a996b550 ar reword 2b43e8b1 2 as squash 37817519 3 8ddef852 4 4814d62b 5 復制代碼備用方案
git merge --squash dev
--squash選項作用:合并后不自動提交,相當于用分支的文件覆蓋當前主干的文件
優點:主干提交記錄非常干凈。
缺點:丟失分支提交記錄。
后語
建議大家多實踐測試,才能理解透徹該命令的使用方法!
推薦使用圖形工具進行操作,方便又不容易出錯!
轉載于:https://juejin.im/post/5c8c549ee51d45257c2f7a28
總結
以上是生活随笔為你收集整理的git rebase 简介的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 2022北京冬奥会开幕式里的黑科技,闪耀
- 下一篇: 计算机视觉顶会论文复现,计算机视觉论文_