如何从已删除的未合并分支中删除提交?

时间:2017-05-02 06:40:59

标签: git

enter image description here

  • 我意外地创建了一个名称不正确的分支,然后对其进行了提交。
    • 请致电:commit #1feature branch 'A'
  • 我将commit #1中包含的文件复制到临时文件夹。
  • 我意识到我错误地命名它时删除了branch A
  • 然后,我创建了一个分支(让我们称之为feature branch B),并使用正确的名称和'copy&粘贴在我之前的工作中,我将其放入临时文件夹,有效地重新创建commit #1
    • 让我们将此commit #2称为feature branch B
  • 我继续工作,完成feature branch B,然后发布到develop& master

如何从git历史记录中完全删除commit #1feature branch A并使其看起来从未发生过?

2018年4月11日

根据documentation,我的“鬼”分支是一个跟踪分支。

2 个答案:

答案 0 :(得分:2)

要删除远程分支,您需要运行:

git push --delete origin your-remote-branch-name

要删除本地分支,您需要运行:

git branch -d your-local-branch

如果这给出了一个错误,说它没有完全合并,那么使用:

git branch -D your-local-branch

不要担心提交,你不应该从git中删除提交。此外,您应该刚刚在该提交上创建了一个具有正确名称的分支,并使用旧名称删除了分支,而不是复制工作并重新创建分支

答案 1 :(得分:0)

git branch -rd <name of ghost branch>

  • git branch -v未显示旧分支(即看起来已删除)
  • git branch -va显示分支仍然被引用
  • git branch -d <name of ghost branch> 工作
  • git branch -rd 工作
相关问题