DEV Community

Kazi Abdur Rakib
Kazi Abdur Rakib

Posted on

pull the changes up to a specific commit and delete all commits made after it

To pull the changes up to a specific commit and delete all commits made after it, you can follow these steps:

  1. Identify the commit hash:

    • Use git log to find the commit hash of the commit you want to revert to.
    • Let's assume the commit hash is CODE OF SHA.
  2. Reset your local branch:

    • Use the following commands to reset your local branch to the specified commit:
     git reset --hard (CODE OF SHA)
    
  3. Force-push to the remote repository:

    • If you've already pushed the commits you want to delete, you'll need to force-push the changes to the remote repository:
     git push origin main --force
    

    Be cautious with --force as it overwrites the remote branch with your local branch.

After completing these steps, your local and remote repositories should be rolled back to the state of the specified commit (30c87bb1797c6ac8f4afde9e0004d723f21fe8d5), and all commits made after that will be deleted.

Keep in mind that force-pushing can cause issues if others are collaborating on the same branch. Use it with caution, especially on shared branches. If others are working on the same branch, communicate with them about the force-push to avoid conflicts.

If you face any issues or have further questions, feel free to ask!

Top comments (0)

SurveyJS custom survey software

JavaScript Form Builder UI Component

Generate dynamic JSON-driven forms directly in your JavaScript app (Angular, React, Vue.js, jQuery) with a fully customizable drag-and-drop form builder. Easily integrate with any backend system and retain full ownership over your data, with no user or form submission limits.

Learn more

đź‘‹ Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay