Webstorm pushes deleted commitments to Git/GitHub
Answered
I recently started studying Full-Stack development and am quite new to all this but so far so good.
Now I'm getting practice on how to manage Git/GitHub repositories from Webstorm and all seems to be clear apart from an "issue" that I'm having. When I push a commit by mistake, I learned to remove them with the git bash,
- I first use the command "git reset --hard HEAD~" followed by the number of commits I want to remove locally.
- Then "git push origin +master --force".
After using these two commands, the commitments disappear from Git and GitHub, but then, if I push a new commitment from Webstorm, they will all appear again making even more confusion.
As I said I'm new and learning, but I'm wondering why this happens, am I doing something wrong, or it's just the way it is?
Thanks in advance,
Giovanni.
Please sign in to leave a comment.
Hello GioFar
Could you please elaborate on when and where exactly commits disappear? If you do "git reset --hard" then it's expected that some commits will disappear locally and when you do "push --force" then these commits will be also deleted on a remote repository.
Hi Ruslan Kuleshov
Apologies for the explanation. Yes, I had to delete some commits, and I used those two commands, one to remove locally, and the other to remove from GitHub, and was fine, they worked as expected, I then continued working on Webstorm, and after a while, I pushed a new commit, and instead of sending only the last one, it also sent the one previously deleted by the git bash.
On the right, you can see the GitHub app showing only one commit, after removing the others with git bash, same in the actual Github website, then down on the Git tab, you can see all the deleted commits still there, and as consequence, when I push, it tries to push them back, as you can see in the Push Commits window above. I can't find a way to remove commits deleted locally and remotely also on Webstorm. Apologies for my English, hopefully was clearer this time.
Thanks.
Ok, after some digging I found the solution. After deleting the commits locally and remotely with the Git Bash and Updating the project in WebStorm, I have to select the commits in the Git tab under local, and right-click Drop commit.
Hello GioFar
Essentially, what should be done is right-click on a commit that you want to be the last one, then "Reset current branch to here"
Choose "hard" there, make sure that the git log contains desired commits and then you need to do "Force push"
But based on "git push origin +master --force" it looks like you are using git worktree - am I correct?
Hi Ruslan Kuleshov
Thank you very much for the help, now I start putting the pieces together.
I did already try those steps, but always failed because I have never been able to do a force push, but now I finally found the reason why.
As I said at the very beginning, I just started learning, for my testing I was working on the master branch, and I just found out that on the Git settings there is an entry where the Master it's set as protected branches, I removed it from there temporary just to test, and now all work as expected.
Thank you.