git命令:将多个commit提交记录修改为1条
本人也是最近2周才開始使用git,有些也理解不到位,在工作中實操之后記錄下來,工作環境linux ubuntu。
變基時有六個命令可用:
pick
pick只是意味著包括提交。重新進行命令時,重新安排pick命令的順序會更改提交的順序。如果選擇不包括提交,則應刪除整行。
reword
該reword命令與相似pick,但是使用后,重新設置過程將暫停并為您提供更改提交消息的機會。提交所做的任何更改均不受影響。
edit
如果您選擇edit提交,則將有機會修改提交,這意味著您可以完全添加或更改提交。您還可以進行更多提交,然后再繼續進行變基。這使您可以將大型提交拆分為較小的提交,或者刪除在提交中所做的錯誤更改。
squash
該命令使您可以將兩個或多個提交合并為一個提交。提交被壓縮到其上方的提交中。Git使您有機會編寫描述這兩個更改的新提交消息。
fixup
這類似于squash,但是要合并的提交已丟棄其消息。提交僅合并到其上方的提交中,并且較早提交的消息用于描述這兩個更改。
exec
?
命令是:git rebase -i HEAD~n
其中n代表的是將要n條commit log合并為一個commit log,然后進入一個界面,按i進行vim編輯
pick 8b485bc add 4 pick a75ed75 add 5# Rebase 63ce9fc..a75ed75 onto 63ce9fr (2 command(s)) # # 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 # d, drop = remove commit # # 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 ~ ~下面注釋的是提示,我們不需要管,只要專注前兩行就行
?
然后,第二行的pick改為s,表示將第二個commit合并到第一個comit中。
?
如果需要修改commit信息,可以進行修改,然后修改注釋,最后保存退出。
總結
以上是生活随笔為你收集整理的git命令:将多个commit提交记录修改为1条的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: MySQL字符串拼接、分组拼接字符串
- 下一篇: 2019华为杯研究生数学建模竞赛总结(E