本文介绍了如何从LOG中删除'git commit',就像它从来没有存在过的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在其中一个提交中犯了一个错误。现在我想完全删除这个提交,所以它看起来从来没有存在过。我不希望在日志中看到这一点。



我尝试了,但我可以在日志中看到提交。如何完全删除它?



- 编辑 -



好吧,我不完全给信息。 Kevin Ballard 是正确的。



现在,我不会推送这个提交,它只在我的机器上。 ouah 解答工作,命令

  git log 

不会显示,但是命令是什么

  git reset --hard HEAD ^ 

do ischekout last commit and the the branch to this ,所以我继续看到一个像这样的图形程序。



- 编辑2 -



不,这是一个SmartGit错误!提交确实消失了。我必须关闭日志的窗口,然后再打开。如果它是最后一次提交的话,那么

就不会再有提交了。

  git reset --hard HEAD ^ 

如果不是最后一次提交

  git rebase -i commit_hash ^ 

一个编辑器会打开,用commit,save和quit删除整行。

注意重写历史记录或重新分派,如果分支已被推送通常是一个坏主意,你可能更喜欢使用

  git revert commit_hash 

会添加一个新的提交来恢复提交 commit_hash


I have made a mistake in one of the commits. Now I want to completely delete this commit, so it looks like it has never existed. I don't want to see this in log.

I have tried all tips from this question ("How to delete a 'git commit'"), but I can see the commit in the log. How I can completely delete it?

-- Edit --

Ok, I do not give the completely information. Kevin Ballard are correct.

By now, I do not push this commit, it's only in my machine. The ouah answer work, the command

git log

will not show, but what the command

git reset --hard HEAD^

do is "chekout last commit and change the the branch to this", so I continue seeing that commit with a graph program like SmartGit.

--Edit 2--

No, this is a SmartGit bug!!!! The commit really disappear. I have to close the windows of log and than open again. The commit is no more there.

解决方案

If it is the last commit

git reset --hard HEAD^

if it is not the last commit

git rebase -i commit_hash^

an editor will open, delete the whole line with the commit, save and quit.

Note that rewriting history or rebasing if the branch has already been pushed is usually a bad idea and you may prefer to use

git revert commit_hash

that will add a new commit that reverts the commit commit_hash.

这篇关于如何从LOG中删除'git commit',就像它从来没有存在过的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-30 02:18