Delete a "dead-end" commit. How do I do it?

I renamed a commit and now I have this terrible branching. How do I destroy, undo the second commit (“Добавлены дополнительные тесты”), make all of it a straight line so that I can squash the commits and push it to a remote repository? I keep firing at it with everything at my disposal: I tried “Undo Commit”, “Drop Commit”, but it still stays on! Please give IntelliJ-specific guidance

1 Like

You don’t use git in terminal? I’ve never used it in IntelliJ :frowning:

Hi @nad.chel, before I answer your question,
I want to assure you that having different branching is perfectly fine, and it doesn’t have to be a straight line.
Also, it’s important to note that nothing is truly deleted in git, unless it’s an unreacted point await to be gc, or you remove your entire .git file from your project, which you should X avoid doing X, lol

As for your question about IntelliJ, I’m not very familiar with it, so I may not read the message correctly.

Does the little tag represent a branch in IntelliJ?
If so, the easiest way to fix it, and with no harm, you can simply to remove the branch name from “Добавлены дополнительные тесты”. When there is no branch pinning commit-point to a line, it will disappear.
( it will still exist somewhere in the git universe, but at least you won’t see it anymore )

if not?
And how did you change your commit name, did you use git commit --amend -m "new name" ? or something else?

I can’t see your commit num right here. I will leave my suggestion anyway, but if you can’t understand, then leave it. don’t follow my step:

Try switching to the branch of “Добавлены дополнительные тесты”, and do git reset HEAD~1 will release the change file you had done back to your working stage. you decide to keep it or not. or simply XwarningX git reset HEAD~1 --hard XwarningX
and will be like this below:

then switch/checkout back to the branch you want, it will be like a new line

hope it helps. But make sure you understand what you are doing, or just leave it, it’s fine.

1 Like