Our team is doing several projects in PHP. We have wrongly committed a folder of One Project to another. Now, we want to remove that particular commit from the Project. If we remove the particular folder/commit from the project then there is no issue for our project.
If we just remove the folder and issue the new commit at the current position then the folder is removed but it will remain in the history of Git. So, we want to remove it completely from refs, history and other things from Git.
We can also create a separate branch but the commit refs of authors would be lost. We want to only remove that particular commit. We have no issue in rewriting history or re-basing it but don't know how to do it.
In the project we have done 136 commits and want to remove commit no.76th. The required information about SHA is as under
5d39775b //136th commit
a4df5ee9 //135th commit
6971cf35 //134th commit
.....
....
162f833c //76th commit
32603274 //75th commit
.....
....
9770059 //1st commit
To remove the last commit from git, you can simply run git reset --hard HEAD^ If you are removing multiple commits from the top, you can run git reset --hard HEAD~2 to remove the last two commits. You can increase the number to remove even more commits.
Deleting the "Middle" Commit from the History. All you need to do is typing "drop" at the beginning of each commit you want to delete. Be careful while using the git rebase command, as it may cause sudden problems.
In order to remove a specific file from a Git commit, use the “git reset” command with the “–soft” option, specify the commit before HEAD and the file that you want to remove.
In your master branch, you can interactively rebase:
git rebase -i 162f833c^
This will rebase on top on the commit before the offending commit. Now just remove the offending commit from the list, save, and exist the editor (default in *nix platforms is vi).
This will rebase your branch on top the commit before the problematic one, without it, which seems to be what you're trying to achieve.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With