-4

I committed and pushed my changes on a remote repo on Gitlab as all worked fine. After more tests I found that what I committed didn't work. Now that I resolved all the issues I had with these bad commits, how do I undo them and have new ones in the git history? It is not the commit message that I have problem with, it's the content of the files that I committed. I want to clean up my commits and have only working commits working, is there any solution aside from having to force delete my commits on the remote repo ?

  • Possible duplicate of [How to modify existing, unpushed commit messages?](https://stackoverflow.com/questions/179123/how-to-modify-existing-unpushed-commit-messages) – phd Sep 12 '19 at 10:12
  • 1
    https://stackoverflow.com/search?q=%5Bgit%5D+modify+pushed+commits – phd Sep 12 '19 at 10:13
  • ‘*I want to clean up my commits and have only working commits working*’ Why?! That’s not how it’s ususally done. If you want to experiment, use a branch. – Biffen Sep 12 '19 at 12:38

1 Answers1

3

If you have fixed the code than there is no need for undo of commits. Just commit the new changes for fixes and push the code. If you undo the commits it will create a new history for that commits

  • I don't want to have the old commits as they are incorrect, I'm still learning to use git so I just know the basic commands. – Salma raiss Sep 12 '19 at 12:31
  • You can't remove commits permanently. They will always showing in history.You can revert the commits. or rebase the commits. – Charanjeet Singh Sep 12 '19 at 12:48
  • Charanjeet is correct. Git is designed so that you shouldn't be removing old commits. You just move forward, fixing things. There are ways to 'rewrite' history but it should be avoided unless absolutely necessary (for example, to remove sensitive information committed accidentally). If it's not sensitive, just commit with the fix and move on. No one is looking at your old commits :) – Drew Blessing Sep 13 '19 at 18:45