Is ther开发者_如何转开发e anyway for me to delete my github commit history? I don't want to lose all my commits, just the last 10 or so that were pushed to github. I can't seem to figure out how to do this.
Just pick the hash you want to go back to and in your clone do:
git reset --hard hash#
git push -f origin branch
where branch
is the name of the branch you want to push. Voilà. Be carefully with the force push. You may want to copy your working directory until you are familiar with it.
If you want to do this, you can use HEAD~10
git reset --hard HEAD~10
git push -f origin master
It is not recommended to do delete server commit history, especially: if you have a team of people working on this repo.
If you have a team of people working on this, I would recommend to fall back by adding another commit that undo your code you don't want.
I had uploaded all of my files to my first github project, including some settings files with secret keys. I had to go back and remove all the versions that were included before I added my .gitignore
file, and deleted all settings files from my project's cache.
How I did this:
gedit ./.git/logs/HEAD
Find the 40-character SHA hash of the 'new root' you wish to delete everything prior to. Copy it to the clipboard and close it. (You may or may not use gedit
, a default text editor for linux).
$> gedit ./.git/info/grafts
Paste the SHA here. Go to your project's directory.
$> cd ../..
$> git filter-branch
Force the push to the master, otherwise it will block your attempt to erase your history.
$> git push --force -u origin master
Delete your grafts
file.
$> rm ./.git/info/grafts
NEVERMIND
Well, my answer is only half the battle. My public activity RSS feed still has links to all the diffs that detail the very information I wanted to remove. Apparently, there is no way to delete this, but you should probably read Change your Password, and update any sensitive data you may have accidentally uploaded.
With Git installed, you could also right-click your repository folder - Git GUI Here.
Select Repository - Visualize All Branch History.
Right-click the desired commit - Reset master branch history to here.
Now you have 3 options:
Once chosen, select File - Reload.
Managed to figure this out after selecting Revert on a commit in GitHub Desktop, then Revert again so we're back to the original code, then simply wishing to clean up these couple Revert commits.
精彩评论