我无意中修改了之前的承诺。提交应该是单独的,以保存我对特定文件所做的更改的历史记录。
有没有办法撤销最后的承诺?如果我执行类似gitreset-hardHEAD^的操作,第一次提交也会被撤销。
(我还没有推送到任何远程目录)
我无意中修改了之前的承诺。提交应该是单独的,以保存我对特定文件所做的更改的历史记录。
有没有办法撤销最后的承诺?如果我执行类似gitreset-hardHEAD^的操作,第一次提交也会被撤销。
(我还没有推送到任何远程目录)
当前回答
也许可以使用git-relog在修改前和修改后获得两个提交。
然后使用git diff before_commit_id after_commit_id>d.diff获取修正前和修正后的差异。
接下来使用git checkout before_commit_id返回提交前
最后使用git-apply.diff应用您所做的真正更改。
这解决了我的问题。
其他回答
您可以执行以下操作来撤消git提交-修改
git reset—软头^git签出文件_from_old_commit_onbranchgit拉动原点your_branch_name
====================================
现在,您的更改与之前相同。所以你已经完成了gitcommit的撤销-修改
现在您可以执行gitpushorigin<your_branch_name>,以推送到分支。
您需要做的是创建一个新的提交,其详细信息与当前HEAD提交相同,但父级与先前版本的HEAD相同。gitreset-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.)
# The -C option takes the given commit and reuses the log message and
# authorship information.
git commit -C HEAD@{1}
使用上次提交签出到临时分支git分支临时HEAD@{1}重置上次提交数字复位温度现在,您将拥有您提交的所有文件以及以前提交的文件。检查所有文件的状态。git状态从git阶段重置提交文件。git重置myfile1.js(依此类推)重新附加此提交gitcommit-C HEAD@{1}将文件添加并提交到新提交。
使用ref日志:
git branch fixing-things HEAD@{1}
git reset fixing-things
然后,您应该只在工作副本中保存所有以前修改过的更改,然后可以再次提交
要查看以前索引的完整列表,请键入git-relog
这晚了将近9年,但没有看到这个变体提到完成相同的事情(这是其中一些的组合,类似于顶级答案(https://stackoverflow.com/a/1459264/4642530).
搜索分支上所有分离的标头
git reflog show origin/BRANCH_NAME--date=相对
然后找到SHA1哈希
重置为旧SHA1
git reset—硬SHA1
然后将其向后推。
git推送原点BRANCH_NAME
完成。
这将使您完全恢复到原来的提交状态。
(包括先前覆盖的分离提交头的日期)