"Unpushed" from Git remote branch

✅ SAFE (Recommended): Revert the pushed commit

  1. Find the commit you pushed

    git log --oneline

    Copy the commit hash (e.g. abc1234).

  2. Revert that commit

    git revert abc1234

    Git creates a new commit that undoes the changes.

    If multiple commits:

    git revert abc1234..HEAD
  3. Push the revert

    git push

✅ Best practice for shared branches

⚠️ DANGEROUS (Only if you are 100% sure)
Use this only if you are the only one working on the branch or it’s a personal feature branch:

  • Reset and force-push

    git reset --hard HEAD~1
    git push --force

This will remove the commit locally and rewrite remote history ❌.

If the pushed commit was a deletion and you want to restore a file:

git checkout HEAD~1 -- path/to/file
git commit -m "Restore accidentally deleted file"
git push

Which one should YOU use?

Situation Command
Shared branch
git revert <commit>
Personal branch
git reset --hard + git push --force
Only want to undo 1 file
git revert

Total page views:

Comments

Popular posts from this blog

Useful aliases

Start all Docker containers