If you are using github to share your works with others or even to save your codes as Gist for future uses you probebly know the best way to share your files is using Github Desktop Software which will makes you almost no need any code typing in your Terminal/CMD (ALMOST).

 

In this article we will discus these:

  1. What is Github
  2. What is Git
  3. How to Delete Commits from your Github Repository

 

What is Github?

GitHub is a web-based Git or version control repository and Internet hosting service. It is mostly used for code. It offers all of the distributed version control and source code management functionality of Git as well as adding its own features. Wikipedia
 

What is Git?

Git is a free and open source distributed version control system designed to handle everything from small to very large projects with speed and efficiency. Git is easy to learn and has a tiny footprint with lightning fast performance. Wikipedia
 
 

How to Delete Commits from your Github Repository

For this tutorial you need to download

And install it on your system, both has version for Windows/Mac & Linux OS.

After you install both on your system you need to restart your system once and then you are good to go.

 

Now, open your Github software and login to your account.

From file tab in your github software you can create new repository, add new repository if you have in your system or clone existed repository from your github account to your system.

 

Now after creating new repository if you go to C:\Users\{username}\Documents\GitHub you will see your repository there.

Next Step:

For sake of testing we will go to upload an image into our repository and then will delete it to add 2 commints in our repository.

 

  • Choose any image in your system and copy it in your repository folder in your computer.

Now go back to your Github software and you'll see your file there.

  • Add new commit (explain about this file that you want to upload eg. new demo image.)

  • Hit Commit to master
  • After that you have to push origin in top of your software

Now if you go and check your repository on Github you'll see your new file(s) there.

 

 

Removing Process:

First of all delete file(s) from your repository in your system and you'll notice changes to your Github Software.

As we did for uploading our file now you have to write commit for deleting as well and hit Commit to master.

Then Push origin again.

Now if you check your Github repository you'll see that your file(s) are deleted.

But wait! what about commits that we created?

You can see your commits from your Github Software History tab or from your Github repository. As you see we have now two more commits since we started this tutorial.

This is how we delete those.

 

Remember we installed Git early this tutorial?

  1. Open Git Bash in your system.
  2. Go to your repository folder.

After you are in your repository folder type this code:

git reset --hard HEAD~1

If you want to delete both commits type this:

git reset --hard HEAD~2

Now you'll notice that commits are removed from your Github software History but still exist in your repository in github! and this part is all this tutorial about cool

 

Type this code in your Git Bash while you are in your repository.

git push --force

 

And now you can check your repository commits in github and is no more commits about the file(s) that we just added / removed.

 

 

What do you think about this tutorial? share your opinion with us in comments and share this post with your friends.

 

Share this article:

Comments