CB *_*ley 2095
您需要做的是创建一个新提交,其具有与当前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}
Run Code Online (Sandbox Code Playgroud)
kni*_*ttl 125
使用ref-log:
git branch fixing-things HEAD@{1}
git reset fixing-things
Run Code Online (Sandbox Code Playgroud)
然后,您应该只在您的工作副本中进行所有先前修改的更改,并且可以再次提交
查看以前索引类型的完整列表 git reflog
ken*_*orb 64
通过以下方式查找修改的提交:
git log --reflog
Run Code Online (Sandbox Code Playgroud)
注意:--patch
为了清楚起见,您可以添加以查看提交的正文.与...相同git reflog
.
然后将HEAD重置为任何先前的提交,只需通过以下方式:
git reset SHA1 --hard
Run Code Online (Sandbox Code Playgroud)
注意:将 SHA1 替换为您的实际提交哈希.另请注意,此命令将丢失所有未提交的更改,因此您可以先将其存储.或者,使用--soft
保留最新更改然后提交它们.
然后樱桃挑选你需要的其他提交:
git cherry-pick SHA1
Run Code Online (Sandbox Code Playgroud)
Ois*_*ley 33
使用 的这些答案都不HEAD@{1}
适合我,所以这是我的解决方案:
git reflog
d0c9f22 HEAD@{0}: commit (amend): [Feature] - ABC Commit Description
c296452 HEAD@{1}: commit: [Feature] - ABC Commit Description
Run Code Online (Sandbox Code Playgroud)
git reset --soft c296452
您的临时环境现在将包含您不小心与 c296452 提交合并的所有更改。
Ark*_*nez 24
您始终可以从手册中拆分提交
utz*_*coz 14
也许可以git reflog
在修改之前和修改之后使用两次提交.
然后用于git diff before_commit_id after_commit_id > d.diff
在修改之前和修改之后获得差异.
接下来用于git checkout before_commit_id
在提交之前返回
最后用于git apply d.diff
应用你所做的真正改变.
这解决了我的问题.
小智 10
您可以执行以下操作来撤消您的 git commit —amend
git reset --soft HEAD^
git checkout files_from_old_commit_on_branch
git pull origin your_branch_name
====================================
现在您的更改与以前一样。所以你完成了撤销git commit —amend
现在您可以执行git push origin <your_branch_name>
, 推送到分支。
差不多晚了 9 年,但没有看到提到的这种变化可以完成同样的事情(它是其中一些的组合,类似于顶级答案(/sf/answers/102148511/) .
搜索分支上的所有分离头
git reflog show origin/BRANCH_NAME --date=relative
然后找到SHA1哈希
重置为旧的 SHA1
git reset --hard SHA1
然后再向上推。
git push origin BRANCH_NAME
完毕。
这将使您完全恢复到旧提交。
(包括之前覆盖的分离提交头的日期)
如果您已将提交推送到远程,然后错误地修改了该提交的更改,则可以解决您的问题。发出a git log
在提交之前找到SHA。(这假设远程被命名为origin)。现在,使用该SHA发出这些命令。
git reset --soft <SHA BEFORE THE AMMEND>
#you now see all the changes in the commit and the amend undone
#save ALL the changes to the stash
git stash
git pull origin <your-branch> --ff-only
#if you issue git log you can see that you have the commit you didn't want to amend
git stash pop
#git status reveals only the changes you incorrectly amended
#now you can create your new unamended commit
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
284371 次 |
最近记录: |