亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

如何撤消已完成的“ git commit --amend”而不是“ git commit”

如何撤消已完成的“ git commit --amend”而不是“ git commit”

Git
萬千封印 2019-11-21 10:21:32
我不小心修改了以前的提交。提交應該分開進行,以保留我對特定文件所做更改的歷史記錄。有什么方法可以撤消上一次提交?如果我做類似的事情git reset --hard HEAD^,那么第一次提交也將被撤消。(我尚未推送到任何遠程目錄)
查看完整描述

3 回答

?
慕田峪9158850

TA貢獻1794條經驗 獲得超7個贊

您需要做的是創建一個新提交,其詳細信息與當前HEAD提交相同,但其父級為的早期版本HEAD。git reset --soft將移動分支指針,以便下一次提交發生在與當前分支頭所在位置不同的提交之上。


# Move the current head so that it's pointing at the old commit

# Leave the index intact for redoing the commit.

# HEAD@{1} gives you "the commit that HEAD pointed at before 

# it was moved to where it currently points at". Note that this is

# different from HEAD~1, which gives you "the commit that is the

# parent node of the commit that HEAD is currently pointing to."

git reset --soft HEAD@{1}


# commit the current tree using the commit details of the previous

# HEAD commit. (Note that HEAD@{1} is pointing somewhere different from the

# previous command. It's now pointing at the erroneously amended commit.)

git commit -C HEAD@{1}


查看完整回答
反對 回復 2019-11-21
?
一只名叫tom的貓

TA貢獻1906條經驗 獲得超3個贊

通過以下方式查找修改后的提交:


git log --reflog

注意:--patch為了清楚起見,您可以添加以查看提交的正文。與相同git reflog。


然后通過以下方法將HEAD重置為以前的任何提交:


git reset SHA1 --hard

注意:將 SHA1 替換為實際的提交哈希。另請注意,此命令將丟失所有未提交的更改,因此您可以將它們存放在前面。或者,改用--soft保留最新的更改,然后提交。


然后在它上面挑選另一個提交:


git cherry-pick SHA1


查看完整回答
反對 回復 2019-11-21
  • 3 回答
  • 0 關注
  • 983 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號