Skip to main content
added 121 characters in body
Source Link
Holger Just
  • 56.5k
  • 15
  • 124
  • 137

You basically have two options to revert changes:

  1. create a new commit which applies reverse changes. This is the preferred option as it doesn't changes history on a public repository
  2. Remove the commits and force push them.

The first option can be achieved by using git revert

git-revert - Revert some existing commits

Given one or more existing commits, revert the changes that the related patches introduce, and record some new commits that record them.

An example would be git revert -n HEAD~5..HEAD. This command creates 5 new commits, each of which undoes one of the last 5 commits of the currently checked out branch.

The second option would be to actually remove the commits. Note that this changes history in the repository. So anyone who has already pull the changes will probably be rather surprised and things can get messy quickly. That said, you can do

git reset --hard HEAD~5 git push --force 

The first command will wipe any uncommitted changes in your current working copy. and reset your local repository to the state of the current HEAD - 5 commits. The second command will force-push to the default remote (i.e. GitHub) There, any changes diverging from your current local repository are overwritten.

A note of warning again: If you don't really know what you are doing, don't use this option as it can lead to data loss for you or others if not done right. Use the first option instead as it will transparently remove changes but without the nasty side-effects of history-rewriting.

You basically have two options to revert changes:

  1. create a new commit which applies reverse changes. This is the preferred option as it doesn't changes history on a public repository
  2. Remove the commits and force push them.

The first option can be achieved by using git revert

git-revert - Revert some existing commits

Given one or more existing commits, revert the changes that the related patches introduce, and record some new commits that record them.

An example would be git revert -n HEAD~5..HEAD

The second option would be to actually remove the commits. Note that this changes history in the repository. So anyone who has already pull the changes will probably be rather surprised and things can get messy quickly. That said, you can do

git reset --hard HEAD~5 git push --force 

The first command will wipe any uncommitted changes in your current working copy. and reset your local repository to the state of the current HEAD - 5 commits. The second command will force-push to the default remote (i.e. GitHub) There, any changes diverging from your current local repository are overwritten.

A note of warning again: If you don't really know what you are doing, don't use this option as it can lead to data loss for you or others if not done right. Use the first option instead as it will transparently remove changes but without the nasty side-effects of history-rewriting.

You basically have two options to revert changes:

  1. create a new commit which applies reverse changes. This is the preferred option as it doesn't changes history on a public repository
  2. Remove the commits and force push them.

The first option can be achieved by using git revert

git-revert - Revert some existing commits

Given one or more existing commits, revert the changes that the related patches introduce, and record some new commits that record them.

An example would be git revert -n HEAD~5..HEAD. This command creates 5 new commits, each of which undoes one of the last 5 commits of the currently checked out branch.

The second option would be to actually remove the commits. Note that this changes history in the repository. So anyone who has already pull the changes will probably be rather surprised and things can get messy quickly. That said, you can do

git reset --hard HEAD~5 git push --force 

The first command will wipe any uncommitted changes in your current working copy. and reset your local repository to the state of the current HEAD - 5 commits. The second command will force-push to the default remote (i.e. GitHub) There, any changes diverging from your current local repository are overwritten.

A note of warning again: If you don't really know what you are doing, don't use this option as it can lead to data loss for you or others if not done right. Use the first option instead as it will transparently remove changes but without the nasty side-effects of history-rewriting.

Some clarifications
Source Link
Holger Just
  • 56.5k
  • 15
  • 124
  • 137

You basically have two options to revert changes:

  1. create a new commit which applies reverse changes. This is the preferred option as it doesn't changes history on a public repository
  2. Remove the commits and force push them.

The first option can be achieved by using git revert

git-revert - Revert some existing commits

Given one or more existing commits, revert the changes that the related patches introduce, and record some new commits that record them.

An example would be git revert -n HEAD~5..HEAD

The second option would be to actually remove the commits. Note that this changes history in the repository. So anyone whjowho has already pull the changes will probably be rather suprised Thingssurprised and things can get messy quickly. That said, you can do

git reset --hard HEAD~5 git push --force 

Note that itThe first command will wipe any uncommitted changes in your current working copy. Andand reset your local repository to the state of the current HEAD - 5 commits. The second command will force push-push to the default remote (i.e. GitHub) There, any changes diverging from your current local repository are overwritten.   

I repeat myselfA note of warning again: If you don't really know what you are doing, don't use this option as it can lead to data loss for you or others if not done right. Use the first option instead as it will transparently remove changes but without the nasty side-effects of history-rewriting.

You basically have two options to revert changes:

  1. create a new commit which applies reverse changes. This is the preferred option as it doesn't changes history on a public repository
  2. Remove the commits and force push them.

The first option can be achieved by using git revert

git-revert - Revert some existing commits

Given one or more existing commits, revert the changes that the related patches introduce, and record some new commits that record them.

An example would be git revert -n HEAD~5..HEAD

The second option would be to actually remove the commits. Note that this changes history in the repository. So anyone whjo has already pull the changes will probably be rather suprised Things can get messy quickly. That said, you can do

git reset --hard HEAD~5 git push --force 

Note that it will wipe any changes in your current working copy. And will force push to the default remote. There, any changes diverging from your current local repository are overwritten.  I repeat myself: If you don't really know what you are doing, don't use this option as it can lead to data loss for you or others if not done right.

You basically have two options to revert changes:

  1. create a new commit which applies reverse changes. This is the preferred option as it doesn't changes history on a public repository
  2. Remove the commits and force push them.

The first option can be achieved by using git revert

git-revert - Revert some existing commits

Given one or more existing commits, revert the changes that the related patches introduce, and record some new commits that record them.

An example would be git revert -n HEAD~5..HEAD

The second option would be to actually remove the commits. Note that this changes history in the repository. So anyone who has already pull the changes will probably be rather surprised and things can get messy quickly. That said, you can do

git reset --hard HEAD~5 git push --force 

The first command will wipe any uncommitted changes in your current working copy. and reset your local repository to the state of the current HEAD - 5 commits. The second command will force-push to the default remote (i.e. GitHub) There, any changes diverging from your current local repository are overwritten. 

A note of warning again: If you don't really know what you are doing, don't use this option as it can lead to data loss for you or others if not done right. Use the first option instead as it will transparently remove changes but without the nasty side-effects of history-rewriting.

Source Link
Holger Just
  • 56.5k
  • 15
  • 124
  • 137

You basically have two options to revert changes:

  1. create a new commit which applies reverse changes. This is the preferred option as it doesn't changes history on a public repository
  2. Remove the commits and force push them.

The first option can be achieved by using git revert

git-revert - Revert some existing commits

Given one or more existing commits, revert the changes that the related patches introduce, and record some new commits that record them.

An example would be git revert -n HEAD~5..HEAD

The second option would be to actually remove the commits. Note that this changes history in the repository. So anyone whjo has already pull the changes will probably be rather suprised Things can get messy quickly. That said, you can do

git reset --hard HEAD~5 git push --force 

Note that it will wipe any changes in your current working copy. And will force push to the default remote. There, any changes diverging from your current local repository are overwritten. I repeat myself: If you don't really know what you are doing, don't use this option as it can lead to data loss for you or others if not done right.