If you accidentally submit something you shouldn't , And push it to Github, There are still ways to delete or modify it . usually , You don't want to mess up Git
Historical record , But in some cases , If you do it right , It's safe .

If it can be avoided , Please don't do that
from Git Deleting submissions from your history is usually a bad idea .Git Designed to track each version of a file , And there are always alternatives to deletion , for example git
revert, It can keep the history intact .

Once it's on a remote repository , such as
Github, It's hard to get rid of submission completely . This is because anyone else who uses the repository will have their own local copy of the repository , Forcibly deleting submissions will make them out of sync .

There are still some reasons to do so —— Maybe you accidentally submitted your private data to a public repository , Whatever you do , It will still be visible in history . This will cause some problems for your colleagues , But even in this case , Forced push can also be used .

<> Repair commit locally

If you work locally , And the changes have not been pushed to Github, You can safely reset or modify submissions that are not remote .Git Your local directory will be tracked , Staging changes internally and keeping them Git
Historical records . All this is synchronized with the remote control , But only when running push/pull. Before you push ,Github I don't care about you repo State of .

If you just made a mistake when submitting the document , You can make a soft reset and make a new submission . If you want to merge multiple submissions into one , This is actually common and useful , be called “ compress ”. If you want to discard the changes completely , You can do the same ( adopt –hard
Reset ).

If you haven't pushed it Github, You can restore recent submissions by soft reset , This will not affect your local files at all , But it'll keep you from talking to me from the beginning Git Submit changes .
git reset --soft HEAD~
If you only want to add new files to recent submissions / change ,Git Built in a logo to do this :
git commit --amend --no-edit
<> recovery (Github security )

If you want to undo what has been pushed to Github
Changes submitted by , Then the safe way is to restore . Restore will generate “ Contrary submission ”, This will essentially undo all changes made to a particular commit . If you add a line , It will be deleted , If you delete a file , It will be added back .

It's safe , Because it doesn't change history , Only new history is added to it . You can push restore submissions to Github, And let your colleagues run git pull To get updates .

first , function git log To get the submission list :

then , copy SHA1 Hash and resume commit :
git recovery 62ff517cc7c358eaf0bffdebbbe1b38dea92ba0f
<> force reset ( unsafe )

If you really want to remove a submission , So the way to do this is to remove it locally , Then force push to Github. Because this is
Very dangerous , And may mess up your colleagues' local repository , If you still want , You may need to Github Forced push branch protection is disabled in the repository settings for :

then , You can delete the submission locally , If it is the latest submission , This is the simplest :
git reset --soft HEAD~
You can also perform interactive rebase, If the submission is not the latest submission , This will be useful . for example , If the submission is 12 Previous submissions , You can change the base from then on , Delete problematic submissions , Then save .
git rebase -i HEAD~12
Once your local repository is working properly , You can force push to Github.
git push origin master --force
Make sure your repo is up to date ! If the remote branch has changes that you do not have , They will be overwritten by this push .

You may want to coordinate this with your team members , Because you may have to ping They and tell them to run fetch and reset:
Bastard git reset origin/master --soft
<> Move commit to a different branch

If you accidentally commit to the wrong branch , And want to delete the commit and move it to the correct branch ,Git There are some tools in that can handle . You can read our mobile submission guide for more information , But the same principle applies
- If you need to delete the submission completely , You must force a reset . If you have no problem with recovery , You can simply restore and pick .

Technology