Remove the last pushed commit from Bitbucket, delete a specific file, and then forcefully push the changes

Last updated on : May 21, 2024 by Ashwini Upadhyay

To remove the last pushed commit from Bitbucket, delete a specific file, and then forcefully push the changes, follow these steps:

1.) Check the Current Branch: Ensure you are on the correct branch where you want to remove the last commit and make changes.

git branch

2.) Remove the Last Commit: Use git reset to remove the last commit. You can either use --soft or --hard depending on whether you want to keep the changes from the commit in your working directory.

Keep the changes (soft reset):

git reset --soft HEAD~1

Discard the changes (hard reset):

git reset --hard HEAD~1

3.) Delete the Specific File: Remove the file you want to delete from your working directory and stage the change.

rm path/to/your/file
git rm path/to/your/file
git commit -m "Remove specific file"

4.) Force Push the Changes: Force push the changes to the remote repository on Bitbucket. This will overwrite the remote branch with your current state.

git push origin branch-name --force

Replace branch-name with the actual name of your branch.

Following these steps should help you remove the last commit, delete a specific file, and forcefully push the changes to your Bitbucket repository.

ashwini upadhyay

Ashwini Upadhyay

I'm a full-stack developer, owner of LogicalDuniya.I love to write tutorials and tips that can help to other artisan. I love to write on PHP, Laravel, Angular, Vue, React, Node, Javascript, JQuery, Codeigniter and Bootstrap from the early stage. I believe in Hardworking and Consistency.

5 1 vote
Article Rating
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments

Press ESC to close