Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8178439
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T23:46:04+00:00 2026-06-06T23:46:04+00:00

I need a commit to no longer be in the git database of commits.

  • 0

I need a commit to no longer be in the git database of commits. I need to be able to remove commit abc123... such that git checkout abc123... returns error: pathspec 'abc123...' did not match any file(s) known to git.

The QA Delete commits from a branch in Git answers this partially, as in how to remove references to a commit from the HEAD, but it doesn’t cover finding all of the branches a commit is present in nor does it cover expiring and purging the commit once it has been made a dangling commit.

How would I achieve this?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-06T23:46:06+00:00Added an answer on June 6, 2026 at 11:46 pm
    1. List all branches that contain the commit:

      git branch --contains COMMITSHA
      
    2. Remove commit from these branches:

      git checkout BRANCH
      git rebase -i COMMITSHA^
      # delete line with commit and save
      

      If a changed branch is tracked in any remote, push it there with override:

      git push --force REMOTE BRANCH
      

      e.g:

      git push --force origin master
      

      (Note that, depending on your development process, the commit may appear in untracked remote branches as well.)

    3. Purge the commit, so it can not be restored from your local repo:

      git reflog expire --all BRANCH1 BRANCH2 # list all branches you changed
      git prune --expire now
      

      Note that you must also run this command on all remote repositories that had this commit. If you have no access to the remote repo, you have to cross your fingers — commit will eventually expire by itself and will be purged by git gc.

      Be warned that above commands will remove all dangling objects from Git repo and all the history of branch changes — so you wouldn’t be able to restore (by non-forensic means) anything lost prior to its run.

    4. Tell all collaborators to fetch changed branches and update any work they might have based on them. They should do as follows:

      git fetch REMOTE      
      

      For each branch that is based on a branch you changed above (including the branch itself if they have it locally):

      git checkout BRANCH
      git rebase REMOTE/BRANCH
      git reflog expire --all BRANCH
      

      After they’re done:

      git prune --expire now
      
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

The git central repository to which I need to commit is configured using SSH
I have some binary files that I don't need to commit. I need them
I need to get patch file for inital commit (which is not empty) for
I need the ability to run an arbitrary command when I try and commit
I need to merge between dev and master frequently. I also have a commit
Need help with a query that I wrote: I have three tables Company id
I'm currently writing a little zsh function that checks all of my git repositories
I need to find the different between two branches by commit ID, not by
I've batchly generated a lot of apk install package, and I need to commit
On branch 'first' I did: git add . git commit -m Finished first changes

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.