[英]How to revert Git soft reset?
我在一個分支上工作,偶然地我做了git reset HEAD~1
因為我以為我要重置我的上一次提交。
問題是我什至沒有提交更改,所以我已經完成了重置以提交由其他人完成的更改。 該提交中的許多更改都是在我也正在處理的文件上完成的,因此我沒有注意到並繼續我的工作。 提交並推送更改后,我發現缺少提交。
develop branch: commitA -> commitB -> commitC
my branch: commitA -> commitB -> myCommit
有什么辦法可以還原這些更改並在提交之前插入commitC
?
您可以通過git reflog
查看工作樹。 首先,返回commitC
並在git log
堆棧的頂部選擇myCommit
。 然后只需更新遠程。
$ git reflog
# copy the commit-hash of 'commitC'
$ git checkout <commitC-hash>
$ git reflog
# copy the 'myCommit-hash'
$ git cherry-pick <myCommit-hash> # take the 'commitC' top
$ git checkout -b 'new-my-branch' # create 'new-my-branch' from current stage
# Replace 'my-branch' with 'new-my-branch'
$ git branch -D my-branch # delete 'my-branch'
$ git checkout -b my-branch # create new 'my-branch' from 'new-y-branch'
$ git push -f origin HEAD # replace remote/my-branch by local/my-branch
你並不需要恢復你的承諾,因為你可以在一台遠程底墊您當地的分行,並在清潔帶來commitC
重新申請所提交的最重要的是前。
我完全不知道你已經在本地完成與分支圖,你給我們結束了,但我認為,你可以簡單地衍合分支上刪除develop
中摳commitC
,然后重播您myCommit
在它的上面:
git fetch origin # bring origin/develop up to date
git checkout develop # checkout local develop branch
git rebase origin/develop # rebase your local branch on the remote one
現在您應該可以通過以下方法簡單地快速轉發遠程分支:
git push origin develop
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.