DEV Community

Benji 🍙
Benji 🍙

Posted on

TIL you can restore deleted files from a commit and then apply a git fixup to update the changes of that commit instead.

  1. 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

  2. (optional) Edit your file if you want to include any change in the commit instead

  3. git commit --edit --fixup [previous_commit_hash]

  4. Rebase with autosquash so you apply the fixup commit to the previous commit hash git rebase --autosquash --interactive origin/master

  5. 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

Image of Timescale

🚀 pgai Vectorizer: SQLAlchemy and LiteLLM Make Vector Search Simple

We built pgai Vectorizer to simplify embedding management for AI applications—without needing a separate database or complex infrastructure. Since launch, developers have created over 3,000 vectorizers on Timescale Cloud, with many more self-hosted.

Read full post →

Top comments (0)

Postmark Image

Speedy emails, satisfied customers

Are delayed transactional emails costing you user satisfaction? Postmark delivers your emails almost instantly, keeping your customers happy and connected.

Sign up