简体   繁体   English

在git amend和git push --force之后安全删除提交

[英]Safely deleting a commit after git amend and git push --force

I am not a git expert and I am trying to save code that I am working on. 我不是git专家,我正在尝试保存正在处理的代码。 I wanted to rename the most recent commit by following the steps described here . 我想按照此处描述的步骤重命名最近的提交。 Particularly, I first ran 特别是我第一次跑

git commit --amend

to correct misspelled commit message using a text editor locally, then 在本地使用文本编辑器纠正拼写错误的提交消息,然后

git push --force

to update GitHub repository. 更新GitHub存储库。 Everything went well except that I still have a (I believe, sorry for a bad terms) upstream changes labeled red in git gui: 除了我在git gui中仍标有红色的上游更改(我相信,不好意思)之外,一切都进行得很顺利:

在此处输入图片说明

That say 那说

Local uncommitted changes, not checked in to index 本地未提交的更改,未签入索引

This red labeled changes are the same as my recently amended commit. 带有红色标记的更改与我最近修订的提交相同。 Running git pull just says that 运行git pull只是说

Already up to date 已更新

So, my question is how to remove those 'duplicate' changes? 因此,我的问题是如何删除那些“重复的”更改? (node labelled red on the picture above). (上图中标记为红色的节点)。 I am afraid that running: git reset --hard HEAD^ will just remove the last amended commit 恐怕运行: git reset --hard HEAD^只会删除最后修改的提交

I solved this issue by simply making changes to the file that was in upstream node (labelled red) captioned 我通过简单地对标题为字幕的上游节点(标记为红色)中的文件进行更改来解决了此问题

Local uncommitted changes, not checked in to index 本地未提交的更改,未签入索引

and committed it. 并承诺。

The "Local uncommitted changes, not checked in to index" were overridden by my new commit 我的新提交覆盖了“本地未提交的更改,未签入索引”

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM