Reputation: 31
I don't know exactly how to use Github, so I made many commits to edit readme.md in Github page.
Can I delete some commits editing readme.md file in Github?
Upvotes: 0
Views: 1434
Reputation: 3106
If you want to edit your readme.md file then you can just keep editing and adding a new commit.
- Add your readme.md file changes
- git add .
- git commit -m "i just added a new title"
- git push origin <branch>
If you want to delete commits so that you can clean up the history. Then you will also lose any code changes that were made in those commits. So be 100% sure that you want to delete the commits before
This will delete the last commit only and will keep your changes in your local in case you need to add them back. From there you can just reset head again to remove
git reset HEAD^. --> Removes last commit but keeps your changes locally
git add . --> Add untracked changes
git reset HEAD --hard --> Reset hard from branch so that remove changes override your local therefore deleting the untracked changes that we tracked on above step
If you want to do more complex stuff like deleting multiple commits or picking which commit exactly to delete then you can follow the following resource to help you understand better
https://www.clock.co.uk/insight/deleting-a-git-commit
Info on commits for reference
A commit, or "revision", is an individual change to a file (or set of files). When you make a commit to save your work, Git creates a unique ID (a.k.a. the "SHA" or "hash") that allows you to keep record of the specific changes commited along with who made them and when. Commits usually contain a commit message which is a brief description of what changes were made.
Sources: https://docs.github.com/en/github/getting-started-with-github/github-glossary#commit
Upvotes: 0