且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

从git存储库中删除未提交的提交

更新时间:2023-12-03 21:52:46

最终它会被git清除,但是你可以查看 git gc
$ b

clean 命令是不同的,而code>

实际上强制垃圾收集。

不会照顾你的。

I have a git commit history like this:

          U
         / 
A---B---C---D---E master

Nothing points to the commit U, but I know its hash. How can I completely remove this commit from my repository as if it never existed? I'm the only person using this repo.

I tried using git rebase, but that can either delete parts of a branch or move commits, but doesn't seem to be able to delete a single commit.

If I do git checkout <hash> and then git reset --hard HEAD~1 I don't see the the commit anymore. Is it actually gone completely or is it still hidden in the repo?

Eventually it will be cleaned up by git, but you can look into git gc to actually force a garbage collect.

The clean command is different and won't take care of this for you.