How to end commit commit return and how to return many commits

It should be simple, but I cannot find it in git-scm .

I make many small commits for a public project, and all my work is bad. I want to delete everything I did. Some of them I just made locally, some I clicked on "master of origin".

The first commit (a week ago) is bdbad86 ... with the most recent of e82401b ...

I just want to make it all go away. I tried to get it back.

 git status # On branch master # You are currently reverting commit e82401b. # (all conflicts fixed: run "git revert --continue") # (use "git revert --abort" to cancel the revert operation) 
  • I can’t figure out how to complete this reversal.
  • I do not want to do each entry separately, I want to delete them all.
+7
git git-revert revert
source share
2 answers

I assume that no one intervenes between your work and that you poorly capture the continuous range in repo history. Otherwise, you will have to get complicated. Suppose your story looks like this:

 e82401b - (master, HEAD) My most recent private commit ... bc2da37 - My first private commit cf3a183 - (origin/master) My most recent bad public commit ... 292acf1 - My first bad public commit 82edb2a - The last good public commit 

The first thing we want to do is knock down commits that you haven't made public yet. You can do this with the following command ( note that your changes will disappear and should be considered unrecoverable ):

 git reset --hard cf3a183 

Equivalent (and more readable):

 git reset--hard origin/master 

Now your view of the repository corresponds to the view in origin/master . Now you want to revert your bad public changes and post them as a commit revert. These instructions are for creating one re-commit.

You can use git revert --no-commit a..b to return all commits starting from commit after a (note that!) And ending with, and turn on, commit b . A reversal will be carried out for you. So here we will do:

 git revert --no-commit 82edb2a..HEAD 

Or, equivalently:

 git revert --no-commit 292acf1^..HEAD 

Remembering that HEAD now points to the same place as origin/master .

After running the revert command, you now have your settings set and ready to commit, so just run the simple git commit -m "Reverting those bad changes I accidentally pushed and made public" .

+4
source share

You can set your repo to any previous commit and all changes after that.

git reset --hard

after that, to click on github, use git push -force origin

visit How do you roll back (reset) the git repository for a specific commit?

0
source share

All Articles