[英]git rebase cannot 'squash' without a previous commit
我曾經一直使用git rebase -i
,但是突然它停止了工作。
git rebase
在我擁有的任何項目中均不起作用,這很奇怪,我懷疑git配置有問題(?)
我已經創建了一個test
庫來顯示我在做什么。
在測試庫中,我有2次提交
$ git日志
commit 8fb921a9a481ef1040ee670af7894bff6055a5b4 (HEAD -> master, origin/master)
Author: Bu Kinoshita
Date: Fri May 25 11:26:05 2018 -0300
test 2
commit 00ffa75caccf0118b9e89bc2bb70c4a7417b223a
Author: Bu Kinoshita
Date: Fri May 25 11:25:39 2018 -0300
test
然后git rebased
從第一次提交git rebased
用提交哈希值重新建立基礎
git rebase -i 00ffa75caccf0118b9e89bc2bb70c4a7417b223a
pick 8fb921a test 2
# Rebase 00ffa75..8fb921a onto 00ffa75 (1 command)
#
# 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
將第一行更改為squash 8fb921a test 2
並保存文件。
錯誤出現
error: cannot 'squash' without a previous commit
You can fix this with 'git rebase --edit-todo' and then run 'git rebase --continue'.
Or you can abort the rebase with 'git rebase --abort'.
在測試庫中,我有2次提交
要使用git rebase
將第二個提交壓縮為第一個提交,您必須將兩個提交重新設置為基准。
由於只有這兩種,所以單獨使用git rebase -i
行不通的。 使用git rebase -i --root
將。
然而,由於只有兩個提交,並希望壁球犯是當前提交,你可以做到這一點,而無需使用git rebase
在所有:
git reset --soft HEAD~1
git commit --amend
這里的缺點是--amend
僅會顯示第一次提交的消息以供編輯; 此時第二次提交的消息將消失。 注意,-- --amend
實際上並不會改變現有的提交; 相反,它將做出一個新提交,其父作為當前提交的父。 在這種情況下,當前的提交是根提交,因此它使用了根提交的父母不存在來進行新的根提交。
你只是朝錯誤的方向擠壓。 向上擠壓而不是向下擠壓..所以,如果您有:
Pick ####
Pick ###
Pick ###
然后以這種方式壓入一個提交:
Pick ###
Squash ###
Squash ###
這種方式之前有一個提交。 如果您需要重命名提交,則可以使用reword而不是pick。 但是保存后會出現一個屏幕,您可以編輯PR審閱會看到的提交消息
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.