git checkout [previous_commit_hash]^ -- [file_path]
a. The ^just specifies the parent commit of the previous commit hash where the file shouldn't have been deleted(optional) Edit your file if you want to include any change in the commit instead
git commit --edit --fixup [previous_commit_hash]
Rebase with autosquash so you apply the fixup commit to the previous commit hash
git rebase --autosquash --interactive origin/master
Force push (with lease) to your feature branch
git push origin [your_branch] --force-with-lease
Any changes in the previous commit are just retained as normal
The other way you can do this (if its the latest commit) is to just git reset HEAD~1
to undo those changes, checkout the file that was deleted so its no longer included, then commit again with the same commit message. You'd still need to force push though since you're rewriting the commit history
Top comments (0)