简体   繁体   中英

Git reset - commit still exists on Github

I have 2 branches, master and develop. On my develop branch I've made some commits and pushed up to Github, lets say it looks like ABCDE . Importantly, I've referenced one of the commits C in a Github issue

However, I need to remove commit C from both local and remote history, and I'm ok losing commits D and E in the process. Essentially resetting history back to B . I did that by doing a hard reset to B , and then force pushing up to Github. I then continued working, adding and pushing another commit F thinking everything was OK. So the branch now looks like ABF

Looking at the state of the branch both locally and on Github, everything seems OK. Develop is now just ABF in both places. However, it seems the commits CDE still exist because when I look at the Github issue, it still references C and I can click through to see the entire commit and all files in the repo at the time of that commit

I'm not sure why this is happening, because when I do a git log --graph I only see ABF

Given I've already done the hard reset and force push, what can I do now to eliminate commits CDE correctly from both my local repo and on Github?

This is how git works. It's stupid. Even though you did reset the branch to commit B the CDE commits still exist as objects inside repositories object database. If you truly want to get rid of them you should delete the files referenced by the commits alongside the trees they are pointing to. I'm pretty sure there is a command for this (probably some ref-log manipulation and cache expiry)

However to truly get rid of the commit (and I may be mistaken here) you'd have to recreate the repository too since you don't push the removal of the commits.

You did removed commits CDE from commit history, and you can double check by reviewing the commit history from https://github.com/account/repo/network .

The commit C you can find in github issue is caused that it related for the issue. Even this commit was deleted in github, but it will always be listed to give the entity information about this issue.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM